Moderators SmOke_N Posted October 19, 2006 Moderators Share Posted October 19, 2006 (edited) This was made for someone that was using FileInstall() wrong and asking for help. Since FileInstall() doesn't allow wildcards, and you must use a string for the source, this simply lets you choose a directory that you want to install, allows you to pick the extension to install or just use the wild card, allows you to choose the destination path, and allows you to choose the flag. It will bring everything up in the edit box, and you can use the copy button to copy the data, then paste it to your script. <snip> Feel free to add, critique, whatever... it was just thrown together quickly. Edit: Fixed version. Edit: Added the option to exclude the drive and directory from 1st parameter of FileInstall. Edit - 2014/12/02 Updated code... uses _FileListToArrayRec to allow recursive option now. Also goes to the computer location rather than homedrive. Note: Yes, there is a recursive option to get all the folders/files, however, I did not add code to check the directory paths and making sure they were created, this was a brain fart moment. But I do not have time at the moment to screw around with that, so if you want recursive and want to keep them installed in their directory paths, you may need to do each folder individually without recurse mode. <snip> Edit2 - 2014/12/02 I think I've fixed the recursion issue, added the choice of saving the hierarchy of the folder, should create the directories for you. I tried this on a huge folder of .au3 files, everything looked right. expandcollapse popup#include <GUIConstantsEx.au3> #include <File.au3> Global $sMyComputerCLSID = "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}" Global $gsDirData = "" Global $ghMain = GUICreate('FileInstall Directory', 600, 380) Global $giOutPut = GUICtrlCreateEdit('', 10, 10, 580, 300) GUICtrlCreateLabel('Extension:', 20, 318, 50, 20, 0x001) Global $giExtension = GUICtrlCreateInput('*', 75, 315, 50, 20) GUICtrlCreateLabel('Destination Path:', 130, 318, 90, 20, 0x001) Global $giDestPath = GUICtrlCreateInput('@TempDir & "\"', 220, 315, 200, 20) GUICtrlCreateLabel('Flag:', 425, 318, 30, 20, 0x001) Global $giFlag = GUICtrlCreateCombo('', 455, 315, 40, 300) GUICtrlSetData($giFlag, '0|1|', '0') Global $giDirDrive = GUICtrlCreateCheckbox("Long Path", 500, 315) Global $giDirRecurse = GUICtrlCreateCheckbox("Dir Recurse", 500, 335) Global $giDirHierarchy = GUICtrlCreateCheckbox("Keep Hierarchy", 500, 355) Global $giGetDir = GUICtrlCreateButton('Directory Get Files', 110, 345, 150, 30) Global $giCopyData = GUICtrlCreateButton('Copy Data', 320, 345, 150, 30) GUISetState() While 1 Switch GUIGetMsg() Case - 3 Exit Case $giGetDir $gsDirData = _GetDirData(GUICtrlRead($giExtension), (GUICtrlRead($giDirDrive) <> 1), _ GUICtrlRead($giDestPath), GUICtrlRead($giFlag), GUICtrlRead($giDirRecurse), _ GUICtrlRead($giDirHierarchy) = $GUI_CHECKED) If Not @error Then GUICtrlSetData($giOutPut, '') GUICtrlSetData($giOutPut, $gsDirData) EndIf Case $giCopyData ClipPut(GUICtrlRead($giOutPut)) EndSwitch WEnd Func _GetDirData($sExt, $bExcludeLongName, $sDestPath, $nFlag, $nRecursive, $bHierarchy) Local $sDir = FileSelectFolder("Select a Directory to FileInstall", $sMyComputerCLSID) If @error Then Return SetError(1, @extended, "") EndIf $nRecursive = ($nRecursive = $GUI_CHECKED) ? 1 : 0 Local $aFiles = _FileListToArrayRec($sDir, "*." & $sExt, 1, $nRecursive, 0, 2) If Not IsArray($aFiles) Then Return SetError(2, @extended, "") EndIf Local $sTDrive, $sTDir, $sTFName, $sTExt Local $sHold = "" _GetExistStr($sDestPath, $sHold) Local $sFinstall = "" Local $sTmpDest = "" Local $sHoldStr = "" If $bHierarchy Then ; main folder searching _PathSplit($sDir, $sTDrive, $sTDir, $sTFName, $sTExt) If StringRight(StringRegExpReplace($sDestPath, "[\\/]+\z", ""), _ StringLen($sTFName)) <> $sTFName Then $sTmpDest = StringRegExpReplace($sDestPath, _ "(\&\s*(?:\x27|\x22)[\\/]+(?:\x27|\x22))", "") & ' & "\' & $sTFName & '\"' If Not StringInStr($sHoldStr, $sTDir & @LF) Then $sHoldStr &= $sTDir & @LF _GetExistStr($sTmpDest, $sHold) EndIf EndIf EndIf Local Static $sScrDir = StringRegExpReplace(@ScriptDir, "\\+\z", "") For $i = 1 To UBound($aFiles) - 1 $sTmpDest = $sDestPath _PathSplit($aFiles[$i], $sTDrive, $sTDir, $sTFName, $sTExt) If $bExcludeLongName Then If $sScrDir = StringRegExpReplace($sTDrive & $sTDir, "\\+\z", "") Then $aFiles[$i] = $sTFName & $sTExt EndIf EndIf If $bHierarchy Then $sTmpDest = StringRegExpReplace($sTmpDest, _ "(\&\s*(?:\x27|\x22)[\\/]+(?:\x27|\x22))", "") & ' & "' & $sTDir & '"' If Not StringInStr($sHoldStr, $sTDir & @LF) Then $sHoldStr &= $sTDir & @LF _GetExistStr($sTmpDest, $sHold) EndIf EndIf $sFinstall &= "FileInstall(""" & $aFiles[$i] & '", ' & $sTmpDest & ", " & $nFlag & ")" & @CRLF Next $sHold &= $sFinstall $sHold = StringTrimRight($sHold, 2) Return $sHold EndFunc Func _GetExistStr($sDestPath, ByRef $sOutData) $sOutData &= 'If Not FileExists(' & $sDestPath & ') Then' & @CRLF $sOutData &= ' Do' & @CRLF $sOutData &= ' DirCreate(' & $sDestPath & ')' & @CRLF $sOutData &= ' Until FileExists(' & $sDestPath & ')' & @CRLF $sOutData &= 'EndIf' & @CRLF EndFunc . Edited December 3, 2014 by SmOke_N ViciousXUSMC, hudsonhock, antonioj84 and 1 other 3 1 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 More sharing options...
Ed_Maximized Posted October 23, 2006 Share Posted October 23, 2006 Good job!!! Everybody needs something like this... with some improvementes I think this must be included in Scite tools...Hasta la vista!Ed ShapedGUI Creator : Shaped gui the easy way!!!Txt2au3 : the easy way to include text files into your program without fileinstall_GUICreateWithTiledBackground : Put a GIF in the background of your formsSQLite Database BrowserAnimated GIF UDF : Put animations in your GUI's Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted October 26, 2006 Author Moderators Share Posted October 26, 2006 (edited) Sped it up by using my version of _FileListToArray(), and added a Directory creator if the install directory doesn't currently exist.expandcollapse popup$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("' & $Dir & '\' & $Files[$iCC] & '", ' & $sRead & ', ' & $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 Edit: AutoIt Code tags removed part of the code in _FileListToArray, switched it to regular code tags. Edit: Updated _FileListToArrayEx() Edited June 17, 2007 by SmOke_N 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 More sharing options...
Ed_Maximized Posted October 27, 2006 Share Posted October 27, 2006 Cool... Keep going!!! ShapedGUI Creator : Shaped gui the easy way!!!Txt2au3 : the easy way to include text files into your program without fileinstall_GUICreateWithTiledBackground : Put a GIF in the background of your formsSQLite Database BrowserAnimated GIF UDF : Put animations in your GUI's Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 17, 2007 Author Moderators Share Posted June 17, 2007 I edited the above, however there was an issue sense I re-wrote _FileListToArrayEx().... See corrected version in post 1. 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 More sharing options...
LuckyMurari Posted June 18, 2007 Share Posted June 18, 2007 a simple but very useful tool Link to comment Share on other sites More sharing options...
uguradem Posted December 11, 2007 Share Posted December 11, 2007 Hi all, Is it possible to use it directly in a script without GUI?? Link to comment Share on other sites More sharing options...
Drew Posted April 29, 2008 Share Posted April 29, 2008 NICE. I LOVE THIS SCRIPT. I just wish I found it sooner... Been trying to think of a way to do this easier for hours. THANK YOU. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted June 11, 2008 Author Moderators Share Posted June 11, 2008 Added the option to exclude the Drive and Directory (Long Path) from the Install, checking "Long Path" will include the full path + file name and extension, un-checking it will exclude the drive and directory only including the file name and extension.Request made: http://www.autoitscript.com/forum/index.php?showtopic=73313 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 More sharing options...
LimeSeed Posted June 11, 2008 Share Posted June 11, 2008 This was made for someone that was using FileInstall() wrong and asking for help. Since FileInstall() doesn't allow wildcards, and you must use a string for the source, this simply lets you choose a directory that you want to install, allows you to pick the extension to install or just use the wild card, allows you to choose the destination path, and allows you to choose the flag. It will bring everything up in the edit box, and you can use the copy button to copy the data, then paste it to your script.expandcollapse popup#include <File.au3> Global $hMain, $hEdit, $hExtension, $hDestPath, $hFlag, $hGetDir, $hCopy Global $sDrive, $sDir, $sFName, $sExt Global $bExcludeScriptDirLongName = True $hMain = GUICreate('FileInstall Directory', 580, 380) $hEdit = GUICtrlCreateEdit('', 10, 10, 560, 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') $hDirDrive = GUICtrlCreateCheckbox("Long Path", 500, 315) $GetDir = GUICtrlCreateButton('Directory Get Files', 100, 345, 150, 30) $hCopy = GUICtrlCreateButton('Copy Data', 310, 345, 150, 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 $bExcludeScriptDirLongName = (GUICtrlRead($hDirDrive) <> 1) 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, '') EndFuncFeel free to add, critique, whatever... it was just thrown together quickly. Edit: Fixed version. Edit: Added the option to exclude the drive and directory from 1st parameter of FileInstall. thanks so much! it was me who was having the problem! Wonderful program!! Made it so easy! global $warming = true Link to comment Share on other sites More sharing options...
Valuater Posted March 21, 2009 Share Posted March 21, 2009 Thanks Ron.... This made my required coding real easy.... 8) Valuater 8) Link to comment Share on other sites More sharing options...
cserrins Posted December 14, 2011 Share Posted December 14, 2011 Would be amazing if this tool could include directories and files inside main directory, and of course reconstruct in @tempdir Wanted to include a portable app with my script. Link to comment Share on other sites More sharing options...
toddcbrf2 Posted January 14, 2012 Share Posted January 14, 2012 Terrific tool, thank you for sharing!!!! “Anyone who has never made a mistake has never tried anything new.”― Albert Einstein Link to comment Share on other sites More sharing options...
Chad2 Posted February 9, 2012 Share Posted February 9, 2012 Fantastic. Made my job that much easier when it came time to compile. 5* from me. Link to comment Share on other sites More sharing options...
orangehat Posted February 15, 2012 Share Posted February 15, 2012 Thank you for this code. Link to comment Share on other sites More sharing options...
stlcardfan70 Posted April 23, 2012 Share Posted April 23, 2012 (edited) Thanks for the code. I modified GUI with a 'Recursive' check box which will create directory structure and fileinstall commands recursively. expandcollapse popup#include <File.au3> Global $hMain, $hEdit, $hExtension, $hDestPath, $hFlag, $hGetDir, $hCopy Global $sDrive, $sDir, $sFName, $sExt Global $bExcludeScriptDirLongName = True $hMain = GUICreate('FileInstall Directory', 580, 380) $hEdit = GUICtrlCreateEdit('', 10, 10, 560, 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') $hDirDrive = GUICtrlCreateCheckbox("Long Path", 500, 315) $GetDir = GUICtrlCreateButton("Directory Get Files", 12, 345, 150, 30) $hCopy = GUICtrlCreateButton("Copy Data", 174, 345, 150, 30) $Recursive = GUICtrlCreateCheckbox("Recursive", 502, 336, 97, 17) $IsRecursive = False 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) If GUICtrlRead($Recursive) = 1 then $IsRecursive = True $Files = _FileListToArrayEx($Dir, '*.' & $Ext, 1,'',$IsRecursive) If IsArray($Files) Then $bExcludeScriptDirLongName = (GUICtrlRead($hDirDrive) <> 1) Dim $sHold = '', $DestPathRoot = GUICtrlRead($hDestPath), $nFlag = GUICtrlRead($hFlag) $sDirHold = 'If Not FileExists("' & $DestPathRoot & '") Then DirCreate("' & $DestPathRoot & '")' & @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 If StringLeft($Files[$iCC],4) = "DIR " Then $DirNameNoRoot = StringTrimLeft($Files[$iCC],StringLen($Dir)+4) $sDirHold &= 'If Not FileExists("' & $DestPathRoot & $DirNameNoRoot & '") Then DirCreate("' & $DestPathRoot & $DirNameNoRoot & '")' & @CRLF Else $FileNameNoRoot = StringTrimLeft($Files[$iCC],StringLen($Dir)) $sHold &= 'FileInstall("' & $Files[$iCC] & '", "' & $DestPathRoot & $FileNameNoRoot & '", ' & $nFlag & ')' & @CRLF EndIf Next GUICtrlSetData($hEdit, '') GUICtrlSetData($hEdit, StringTrimRight($sDirHold, 2) & @CRLF & StringTrimRight($sHold, 2)) EndIf EndIf $IsRecursive = False 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), ';'), $DestPathRoot, $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 $DestPathRoot &= FileRead($hOutFile) If Not FileExists($hOutFile) Then Return SetError(4, 4, '') FileDelete($hOutFile) If StringStripWS($DestPathRoot, 8) = '' Then SetError(4, 4, '') Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($DestPathRoot), 1), @LF) Local $sHold For $iCC = 1 To $aFSplit[0] If $sExclude And StringLeft($aFSplit[$iCC], _ StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop 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 If StringInStr(FileGetAttrib($sPath & '' & $aFSplit[$iCC]), 'd') Or _ StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then If StringRegExp($aFSplit[$iCC], 'w:') = 0 Then $sHold &= "DIR " & $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= "DIR " & $aFSplit[$iCC] & Chr(1) EndIf EndIf Next If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(4, 4, '') EndFunc Edited April 23, 2012 by stlcardfan70 Link to comment Share on other sites More sharing options...
SpaceCopRookie Posted August 14, 2012 Share Posted August 14, 2012 Thanks for the code. I modified GUI with a 'Recursive' check box which will create directory structure and fileinstall commands recursively. expandcollapse popup#include <File.au3> Global $hMain, $hEdit, $hExtension, $hDestPath, $hFlag, $hGetDir, $hCopy Global $sDrive, $sDir, $sFName, $sExt Global $bExcludeScriptDirLongName = True $hMain = GUICreate('FileInstall Directory', 580, 380) $hEdit = GUICtrlCreateEdit('', 10, 10, 560, 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') $hDirDrive = GUICtrlCreateCheckbox("Long Path", 500, 315) $GetDir = GUICtrlCreateButton("Directory Get Files", 12, 345, 150, 30) $hCopy = GUICtrlCreateButton("Copy Data", 174, 345, 150, 30) $Recursive = GUICtrlCreateCheckbox("Recursive", 502, 336, 97, 17) $IsRecursive = False 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) If GUICtrlRead($Recursive) = 1 then $IsRecursive = True $Files = _FileListToArrayEx($Dir, '*.' & $Ext, 1,'',$IsRecursive) If IsArray($Files) Then $bExcludeScriptDirLongName = (GUICtrlRead($hDirDrive) <> 1) Dim $sHold = '', $DestPathRoot = GUICtrlRead($hDestPath), $nFlag = GUICtrlRead($hFlag) $sDirHold = 'If Not FileExists("' & $DestPathRoot & '") Then DirCreate("' & $DestPathRoot & '")' & @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 If StringLeft($Files[$iCC],4) = "DIR " Then $DirNameNoRoot = StringTrimLeft($Files[$iCC],StringLen($Dir)+4) $sDirHold &= 'If Not FileExists("' & $DestPathRoot & $DirNameNoRoot & '") Then DirCreate("' & $DestPathRoot & $DirNameNoRoot & '")' & @CRLF Else $FileNameNoRoot = StringTrimLeft($Files[$iCC],StringLen($Dir)) $sHold &= 'FileInstall("' & $Files[$iCC] & '", "' & $DestPathRoot & $FileNameNoRoot & '", ' & $nFlag & ')' & @CRLF EndIf Next GUICtrlSetData($hEdit, '') GUICtrlSetData($hEdit, StringTrimRight($sDirHold, 2) & @CRLF & StringTrimRight($sHold, 2)) EndIf EndIf $IsRecursive = False 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), ';'), $DestPathRoot, $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 $DestPathRoot &= FileRead($hOutFile) If Not FileExists($hOutFile) Then Return SetError(4, 4, '') FileDelete($hOutFile) If StringStripWS($DestPathRoot, 8) = '' Then SetError(4, 4, '') Local $aFSplit = StringSplit(StringTrimRight(StringStripCR($DestPathRoot), 1), @LF) Local $sHold For $iCC = 1 To $aFSplit[0] If $sExclude And StringLeft($aFSplit[$iCC], _ StringLen(StringReplace($sExclude, '*', ''))) = StringReplace($sExclude, '*', '') Then ContinueLoop 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 If StringInStr(FileGetAttrib($sPath & '' & $aFSplit[$iCC]), 'd') Or _ StringInStr(FileGetAttrib($aFSplit[$iCC]), 'd') Then If StringRegExp($aFSplit[$iCC], 'w:') = 0 Then $sHold &= "DIR " & $sPath & $aFSplit[$iCC] & Chr(1) Else $sHold &= "DIR " & $aFSplit[$iCC] & Chr(1) EndIf EndIf Next If StringTrimRight($sHold, 1) Then Return StringSplit(StringTrimRight($sHold, 1), Chr(1)) Return SetError(4, 4, '') EndFunc Does this solution with the directory recursion work for anyone? For me it doesn't seem to perform the recursion of sub directories and actually doesn't even end up listing all files right within in the specified main directory (which works fine in the first original version in the first post). I'm afraid at this point I'm too much of an AutoIt newbie to fix it myself, so I would be grateful if someone has an idea (or a different solution). Generally, this seemed to be exactly what I'm looking for. I need to build a simple installer that will copy/replace a bunch of files, but they are too many files to manually type out all the lines of "FileInstall". So, I figured there has to be a better solution. By the way, is the file browsing function used here to select the source directory limited to just showing and browsing the C: drive? Is that a limitation of that function by design? Thanks in advance for any help. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 2, 2014 Author Moderators Share Posted December 2, 2014 Code has been updated, added some options as well that others requested. 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 More sharing options...
Moderators SmOke_N Posted December 3, 2014 Author Moderators Share Posted December 3, 2014 Added the recursion folder hierarchy option 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now