Jump to content

FileInstall Utility


Recommended Posts

Hi everybody

I use this utility to generate fileinstall scripts :

$Main = GUICreate('FileInstall Directory', 500, 380)
$Edit = GUICtrlCreateEdit('', 10, 10, 480, 300)
GUICtrlCreateLabel('Extension:', 10, 318, 50, 20, 0x001)
$Extension = GUICtrlCreateInput('*', 65, 315, 50, 20)
GUICtrlCreateLabel('Destination Path:', 120, 318, 90, 20, 0x001)
$DestinationPath = GUICtrlCreateInput('@TempDir & "\"', 210, 315, 200, 20)
GUICtrlCreateLabel('Flag:', 415, 318, 30, 20, 0x001)
$Flag = GUICtrlCreateCombo('', 445, 315, 40, 300)
GUICtrlSetData($Flag, '0|1|', '0')
$GetDir = GUICtrlCreateButton('Directory Get Files', 80, 345, 100, 30)
$Copy = GUICtrlCreateButton('Copy Data', 220, 345, 100, 30)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case - 3
            Exit
        Case $GetDir
            $Dir = FileSelectFolder('Select a directory to fileinstall', @HomeDrive)
            If Not @error Then
                $Ext = GUICtrlRead($Extension)
                $Files = _FileListToArrayEx($Dir, '*.' & $Ext, 1)
                If IsArray($Files) Then
                    Dim $sHold = '', $sRead = GUICtrlRead($DestinationPath), $nFlag = GUICtrlRead($Flag)
                    $sHold = 'If Not FileExists(' & $sRead & ') Then' & @CRLF & _
                                '    Do' & @CRLF & _
                                '        DirCreate(' & $sRead & ')' & @CRLF & _
                                '    Until FileExists(' & $sRead & ')' & @CRLF & _
                                'EndIf' & @CRLF
                    For $iCC = 1 To UBound($Files) - 1
                        $sHold &= 'FileInstall("' & $Files[$iCC] & '", ' & $sRead & '"\"' & $Files[$iCC] &'", ' & $nFlag & ')' & @CRLF
                    Next
                    GUICtrlSetData($Edit, '')
                    GUICtrlSetData($Edit, StringTrimRight($sHold, 2))
                EndIf
            EndIf
        Case $Copy
            ClipPut(GUICtrlRead($Edit))
    EndSwitch
WEnd

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    $sFilter = StringRegExpReplace($sFilter, '\s*;\s*', ';')
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder
    $sTFolder = $oFSO.GetSpecialFolder(2)
    Local $hOutFile = @TempDir & $oFSO.GetTempName
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead, $sHoldSplit
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC],8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        $sHoldSplit &= '"' & $sPath & $aSplit[$iCC] & '" '
    Next
    $sHoldSplit = StringTrimRight($sHoldSplit, 1)
    If $iRecurse Then
        RunWait(@Comspec & ' /c dir /b /s /a ' & $sHoldSplit & ' > "' & $hOutFile & '"', '', @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c dir /b /a ' & $sHoldSplit & ' /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE)
    EndIf
    $sRead &= FileRead($hOutFile)
    If Not FileExists($hOutFile) Then Return SetError(4, 4, '')
    FileDelete($hOutFile)
    If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft($aFSplit[$iCC], _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                    $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                Else
                    $sHold &= $aFSplit[$iCC] & Chr(1)
                EndIf
            Case 1
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') = 0 And _
                    StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') = 0 Then
                    If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                        $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                    Else
                        $sHold &= $aFSplit[$iCC] & Chr(1)
                    EndIf
                EndIf
            Case 2
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Or _
                    StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then
                    If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                        $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                    Else
                        $sHold &= $aFSplit[$iCC] & Chr(1)
                    EndIf
                EndIf
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc

It's really practice but i want to know how to change the results like this example :

Actual results :

FileInstall("D:\Backup_DD_Externe\AutoIt Development\iSeries V5R2\Install\readmesp.txt", @TempDir & "\TestDirectory", 1)

FileInstall("D:\Backup_DD_Externe\AutoIt Development\iSeries V5R2\Install\readme.txt", @TempDir & "\TestDirectory", 1)

.....

.....

.....

My request results :

FileInstall("readmesp.txt", @TempDir & "\TestDirectory\readmesp.txt", 1)

FileInstall("readme.txt", @TempDir & "\TestDirectory\readme.txt", 1)

.....

.....

.....

Thanks for help and really sorry for my bad english

Link to comment
Share on other sites

well, as far as i am concerned, you can split up the path, and then use only the 2 last parts, which are filename and extension.

but if the fileinstall option will except that, is the next questionj man.

example:

"removed faulty code" sorry for that

That should work, i think...

But for that to work, you should have the file in the same dir as your script.

Damian666

Edited by damian666
and proud of it!!!
Link to comment
Share on other sites

ok, edit man, i have read the helpfile and so should you man, this next text is taken from the helpfile.

"The source path of the file to compile. This must be a literal string; it cannot be a variable."

so this means it cant be defined by a variable like i did in the above example, sorry for that.

so the only way for you to do it the way you want, is to put your script in the same dir so you can use the filename without any directories attached.

i am sorry, but i think that is the only way man :)

Damian666

Edited by damian666
and proud of it!!!
Link to comment
Share on other sites

  • Moderators

Hi everybody

I use this utility to generate fileinstall scripts :

$Main = GUICreate('FileInstall Directory', 500, 380)
$Edit = GUICtrlCreateEdit('', 10, 10, 480, 300)
GUICtrlCreateLabel('Extension:', 10, 318, 50, 20, 0x001)
$Extension = GUICtrlCreateInput('*', 65, 315, 50, 20)
GUICtrlCreateLabel('Destination Path:', 120, 318, 90, 20, 0x001)
$DestinationPath = GUICtrlCreateInput('@TempDir & "\"', 210, 315, 200, 20)
GUICtrlCreateLabel('Flag:', 415, 318, 30, 20, 0x001)
$Flag = GUICtrlCreateCombo('', 445, 315, 40, 300)
GUICtrlSetData($Flag, '0|1|', '0')
$GetDir = GUICtrlCreateButton('Directory Get Files', 80, 345, 100, 30)
$Copy = GUICtrlCreateButton('Copy Data', 220, 345, 100, 30)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case - 3
            Exit
        Case $GetDir
            $Dir = FileSelectFolder('Select a directory to fileinstall', @HomeDrive)
            If Not @error Then
                $Ext = GUICtrlRead($Extension)
                $Files = _FileListToArrayEx($Dir, '*.' & $Ext, 1)
                If IsArray($Files) Then
                    Dim $sHold = '', $sRead = GUICtrlRead($DestinationPath), $nFlag = GUICtrlRead($Flag)
                    $sHold = 'If Not FileExists(' & $sRead & ') Then' & @CRLF & _
                                '    Do' & @CRLF & _
                                '        DirCreate(' & $sRead & ')' & @CRLF & _
                                '    Until FileExists(' & $sRead & ')' & @CRLF & _
                                'EndIf' & @CRLF
                    For $iCC = 1 To UBound($Files) - 1
                        $sHold &= 'FileInstall("' & $Files[$iCC] & '", ' & $sRead & '"\"' & $Files[$iCC] &'", ' & $nFlag & ')' & @CRLF
                    Next
                    GUICtrlSetData($Edit, '')
                    GUICtrlSetData($Edit, StringTrimRight($sHold, 2))
                EndIf
            EndIf
        Case $Copy
            ClipPut(GUICtrlRead($Edit))
    EndSwitch
WEnd

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    $sFilter = StringRegExpReplace($sFilter, '\s*;\s*', ';')
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder
    $sTFolder = $oFSO.GetSpecialFolder(2)
    Local $hOutFile = @TempDir & $oFSO.GetTempName
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead, $sHoldSplit
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC],8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        $sHoldSplit &= '"' & $sPath & $aSplit[$iCC] & '" '
    Next
    $sHoldSplit = StringTrimRight($sHoldSplit, 1)
    If $iRecurse Then
        RunWait(@Comspec & ' /c dir /b /s /a ' & $sHoldSplit & ' > "' & $hOutFile & '"', '', @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c dir /b /a ' & $sHoldSplit & ' /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE)
    EndIf
    $sRead &= FileRead($hOutFile)
    If Not FileExists($hOutFile) Then Return SetError(4, 4, '')
    FileDelete($hOutFile)
    If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft($aFSplit[$iCC], _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                    $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                Else
                    $sHold &= $aFSplit[$iCC] & Chr(1)
                EndIf
            Case 1
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') = 0 And _
                    StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') = 0 Then
                    If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                        $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                    Else
                        $sHold &= $aFSplit[$iCC] & Chr(1)
                    EndIf
                EndIf
            Case 2
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Or _
                    StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then
                    If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                        $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                    Else
                        $sHold &= $aFSplit[$iCC] & Chr(1)
                    EndIf
                EndIf
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc

It's really practice but i want to know how to change the results like this example :

Actual results :

FileInstall("D:\Backup_DD_Externe\AutoIt Development\iSeries V5R2\Install\readmesp.txt", @TempDir & "\TestDirectory", 1)

FileInstall("D:\Backup_DD_Externe\AutoIt Development\iSeries V5R2\Install\readme.txt", @TempDir & "\TestDirectory", 1)

.....

.....

.....

My request results :

FileInstall("readmesp.txt", @TempDir & "\TestDirectory\readmesp.txt", 1)

FileInstall("readme.txt", @TempDir & "\TestDirectory\readme.txt", 1)

.....

.....

.....

Thanks for help and really sorry for my bad english

When I wrote that, It was for simplicity only.

If you have the files in the same directory, then you could add something in the code with _PathSplit() and use the Drive+Dir part, if they = @ScriptDir, then just use the .au3 file name itself.

Or, if you don't feel like coding it, just use a "Replace" in your editor :) ...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

I knew I recognized that code!!

I had the same thought of using _PathSplit() and placing the script in the same directory as the desired include files are in too!.

I also knew you would respond real soon Ron..

Glad I waited to see your response

8)

Guess I got caught up in what I was doing... the update for that option is trivial, it would probably look something like:
#include <File.au3>
Global $hMain, $hEdit, $hExtension, $hDestPath, $hFlag, $hGetDir, $hCopy
Global $sDrive, $sDir, $sFName, $sExt
Global $bExcludeScriptDirLongName = True

$hMain = GUICreate('FileInstall Directory', 500, 380)
$hEdit = GUICtrlCreateEdit('', 10, 10, 480, 300)
GUICtrlCreateLabel('Extension:', 10, 318, 50, 20, 0x001)
$hExtension = GUICtrlCreateInput('*', 65, 315, 50, 20)
GUICtrlCreateLabel('Destination Path:', 120, 318, 90, 20, 0x001)
$hDestPath = GUICtrlCreateInput('@TempDir & "\"', 210, 315, 200, 20)
GUICtrlCreateLabel('Flag:', 415, 318, 30, 20, 0x001)
$hFlag = GUICtrlCreateCombo('', 445, 315, 40, 300)
GUICtrlSetData($hFlag, '0|1|', '0')
$GetDir = GUICtrlCreateButton('Directory Get Files', 80, 345, 100, 30)
$hCopy = GUICtrlCreateButton('Copy Data', 220, 345, 100, 30)
GUISetState()
While 1
    Switch GUIGetMsg()
        Case - 3
            Exit
        Case $GetDir
            $Dir = FileSelectFolder('Select a directory to fileinstall', @HomeDrive)
            If Not @error Then
                $Ext = GUICtrlRead($hExtension)
                $Files = _FileListToArrayEx($Dir, '*.' & $Ext, 1)
                If IsArray($Files) Then
                    Dim $sHold = '', $sRead = GUICtrlRead($hDestPath), $nFlag = GUICtrlRead($hFlag)
                    $sHold = 'If Not FileExists(' & $sRead & ') Then' & @CRLF & _
                                '    Do' & @CRLF & _
                                '        DirCreate(' & $sRead & ')' & @CRLF & _
                                '    Until FileExists(' & $sRead & ')' & @CRLF & _
                                'EndIf' & @CRLF
                    For $iCC = 1 To UBound($Files) - 1
                        If ($bExcludeScriptDirLongName) Then
                            _PathSplit($Files[$iCC], $sDrive, $sDir, $sFName, $sExt)
                            If StringRegExpReplace(@ScriptDir, "\\+\z", "") = StringRegExpReplace($sDrive & $sDir, "\\+\z", "") Then
                                $Files[$iCC] = $sFName & $sExt
                            EndIf
                        EndIf
                        $sHold &= 'FileInstall("' & $Files[$iCC] & '", ' & $sRead & ', ' & $nFlag & ')' & @CRLF
                    Next
                    GUICtrlSetData($hEdit, '')
                    GUICtrlSetData($hEdit, StringTrimRight($sHold, 2))
                EndIf
            EndIf
        Case $hCopy
            ClipPut(GUICtrlRead($hEdit))
    EndSwitch
WEnd

Func _FileListToArrayEx($sPath, $sFilter = '*.*', $iFlag = 0, $sExclude = '', $iRecurse = False)
    If Not FileExists($sPath) Then Return SetError(1, 1, '')
    If $sFilter = -1 Or $sFilter = Default Then $sFilter = '*.*'
    If $iFlag = -1 Or $iFlag = Default Then $iFlag = 0
    If $sExclude = -1 Or $sExclude = Default Then $sExclude = ''
    Local $aBadChar[6] = ['\', '/', ':', '>', '<', '|']
    $sFilter = StringRegExpReplace($sFilter, '\s*;\s*', ';')
    If StringRight($sPath, 1) <> '\' Then $sPath &= '\'
    For $iCC = 0 To 5
        If StringInStr($sFilter, $aBadChar[$iCC]) Or _
            StringInStr($sExclude, $aBadChar[$iCC]) Then Return SetError(2, 2, '')
    Next
    If StringStripWS($sFilter, 8) = '' Then Return SetError(2, 2, '')
    If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, '')
    Local $oFSO = ObjCreate("Scripting.FileSystemObject"), $sTFolder
    $sTFolder = $oFSO.GetSpecialFolder(2)
    Local $hOutFile = @TempDir & $oFSO.GetTempName
    If Not StringInStr($sFilter, ';') Then $sFilter &= ';'
    Local $aSplit = StringSplit(StringStripWS($sFilter, 8), ';'), $sRead, $sHoldSplit
    For $iCC = 1 To $aSplit[0]
        If StringStripWS($aSplit[$iCC],8) = '' Then ContinueLoop
        If StringLeft($aSplit[$iCC], 1) = '.' And _
            UBound(StringSplit($aSplit[$iCC], '.')) - 2 = 1 Then $aSplit[$iCC] = '*' & $aSplit[$iCC]
        $sHoldSplit &= '"' & $sPath & $aSplit[$iCC] & '" '
    Next
    $sHoldSplit = StringTrimRight($sHoldSplit, 1)
    If $iRecurse Then
        RunWait(@Comspec & ' /c dir /b /s /a ' & $sHoldSplit & ' > "' & $hOutFile & '"', '', @SW_HIDE)
    Else
        RunWait(@ComSpec & ' /c dir /b /a ' & $sHoldSplit & ' /o-e /od > "' & $hOutFile & '"', '', @SW_HIDE)
    EndIf
    $sRead &= FileRead($hOutFile)
    If Not FileExists($hOutFile) Then Return SetError(4, 4, '')
    FileDelete($hOutFile)
    If StringStripWS($sRead, 8) = '' Then SetError(4, 4, '')
    Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($sRead), 1), @LF)
    Local $sHold
    For $iCC = 1 To $aFSplit[0]
        If $sExclude And StringLeft($aFSplit[$iCC], _
            StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop
        Switch $iFlag
            Case 0
                If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                    $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                Else
                    $sHold &= $aFSplit[$iCC] & Chr(1)
                EndIf
            Case 1
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') = 0 And _
                    StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') = 0 Then
                    If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                        $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                    Else
                        $sHold &= $aFSplit[$iCC] & Chr(1)
                    EndIf
                EndIf
            Case 2
                If StringInStr(FileGetAttrib($sPath & '\' & $aFSplit[$iCC]), 'd') Or _
                    StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then
                    If StringRegExp($aFSplit[$iCC], '\w:\\') = 0 Then
                        $sHold &= $sPath & $aFSplit[$iCC] & Chr(1)
                    Else
                        $sHold &= $aFSplit[$iCC] & Chr(1)
                    EndIf
                EndIf
        EndSwitch
    Next
    If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1))
    Return SetError(4, 4, '')
EndFunc
having the option to exclude the full path if the script directory was the same as the file it was wanting to input.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Saw Valuater lurking, thought I should change this up a bit to make it a GUI option See: http://www.autoitscript.com/forum/index.ph...t=0#entry254410

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...