sww Posted July 7, 2006 Share Posted July 7, 2006 (edited) v1.2 NEW RELEASE - If you have v1.0 or v1.1, please replace it with this---------------------------------------------------------------------------------------------------------I put this together to save me some time and thought it might be of use to some other people. I haven't gone through it with a fine tooth comb, so any improvement comments would be welcome.Basically you give it a source directory, select whether or not you want it to include all files within subfolders. It then give you all the code you need to copy and paste it into a script.Stuartexpandcollapse popupOpt("TrayIconDebug", 1) ;0=no info, 1=debug line info Opt("TrayIconHide", 0) ;0=show, 1=hide tray icon Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declare Global $PROGRAM_NAME = "Multiple FileInstall() creator" CREATE_LIST() Func CREATE_LIST() Local $SOURCE_FOLDER = "" Local $DESTINATION_FOLDER = "" Local $SUB Local $FLAG Local $SOURCE_LOCATION = "" Local $DESTINATION_LOCATION = "" Local $CODE = "" Local $CODE_FILENAME = _SWWUniqueFilename(@TempDir, ".txt") ;--- Source Folder ------------------------------------------------------------------------------------------- ;Prompt for the source directory $SOURCE_FOLDER = FileSelectFolder("Please select your source directory", "") ;Exit if FileSelectFolder is cancelled If $SOURCE_FOLDER = "" Then Exit ;If the source folder doesn't have a trailing "\" then add a "\" If StringRight($SOURCE_FOLDER, 1) <> "\" Then $SOURCE_FOLDER = $SOURCE_FOLDER & "\" ;------------------------------------------------------------------------------------------------------------- ;--- Destination Folder -------------------------------------------------------------------------------------- ;Prompt for the destination directory $DESTINATION_FOLDER = InputBox($PROGRAM_NAME, "Please complete the destination path (e.g. C:\temp\new_location)") ;Exit if the above InputBox is cancelled or left blank If $DESTINATION_FOLDER = "" Then Exit ;If the destination folder doesn't have a trailing "\" then add a "\" If StringRight($DESTINATION_FOLDER, 1) <> "\" Then $DESTINATION_FOLDER = $DESTINATION_FOLDER & "\" ;------------------------------------------------------------------------------------------------------------- ;--- Set the value of $SUB so that it can be used as a switch in the dir command ----------------------------- If MsgBox(262144+32+4, $PROGRAM_NAME, "Would you like all sub-directories to be included?") = 6 Then $SUB = " /s" Else $SUB = "" EndIf ;------------------------------------------------------------------------------------------------------------- ;--- Set the value of $FLAG that is used in the FileInstall code --------------------------------------------- If MsgBox(262144+32+4, $PROGRAM_NAME, "In the FileInstall code, do you want the 'overwrite existing files' flag on?") = 6 Then $FLAG = 1 Else $FLAG = 0 EndIf ;------------------------------------------------------------------------------------------------------------- ;Get a file structure report and pipe it to a temporary file RunWait(@ComSpec & ' /c dir "' & $SOURCE_FOLDER & '" /b' & $SUB & " > " & @TempDir & "\dirdump.txt", "", @SW_HIDE) Local $X = 0 While 1 $X = $X + 1 $SOURCE_LOCATION = FileReadLine(@TempDir & "\dirdump.txt", $X) If @error <> 0 Then ExitLoop ;When the dir command is run without the subdirectory (/s) switch, the full path isn't outputed, therefore: If $SUB <> " /s" Then $SOURCE_LOCATION = $SOURCE_FOLDER & $SOURCE_LOCATION ;If the path entry is a directory then: If StringInStr(FileGetAttrib($SOURCE_LOCATION), "D") > 0 Then ContinueLoop Else $DESTINATION_LOCATION = $DESTINATION_FOLDER & StringReplace($SOURCE_LOCATION, $SOURCE_FOLDER, "") $CODE = $CODE & 'FileInstall("' & $SOURCE_LOCATION & '", "' & $DESTINATION_LOCATION & '", ' & $FLAG & ")" & @CRLF EndIf WEnd FileDelete(@TempDir & "\dirdump.txt") FileWrite(@TempDir & "\" & $CODE_FILENAME, $CODE) Run("C:\WINDOWS\system32\notepad.exe " & @TempDir & "\" & $CODE_FILENAME) EndFunc Func _SWWUniqueFilename($LOCATION, $EXTENSION) Local $UNIQUE_FILENAME ;Ensure that there is a trailing "\" on the end of the path If StringRight($LOCATION, 1) <> "\" Then $LOCATION = $LOCATION & "\" ;Ensure that there is a leading "." at the start of the extension If StringLeft($EXTENSION, 1) <> "." Then $EXTENSION = "." & $EXTENSION ;If the extension isn't valid return @error 1 If StringLen($EXTENSION) <> 4 Then SetError(1) Return EndIf While 1 ;Create a filename using a random number between 10000000 and 99999999 $UNIQUE_FILENAME = Random(10000000, 99999999, 1) & $EXTENSION ;If the random filename isn't unique, the loop again, otherwise, exit the loop If FileExists($LOCATION & $UNIQUE_FILENAME) = 1 Then ContinueLoop Else Return $UNIQUE_FILENAME EndIf WEnd EndFuncfileinstall_code_creator_v1.2.au3 Edited July 18, 2006 by sww Link to comment Share on other sites More sharing options...
jrmm Posted July 7, 2006 Share Posted July 7, 2006 Your Install app is really awesome. Thanks for sharing. Link to comment Share on other sites More sharing options...
sww Posted July 7, 2006 Author Share Posted July 7, 2006 Thanks, glad you liked it. Stuart Link to comment Share on other sites More sharing options...
WTS Posted July 8, 2006 Share Posted July 8, 2006 this is quite handy.. Link to comment Share on other sites More sharing options...
marfdaman Posted July 8, 2006 Share Posted July 8, 2006 The idea is very nice indeed, one suggestion though: instead of letting the user type in the destination, examine FileSelectFolder Think I'll be using this sometimes! Alzo Don't take my pic to serious...~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~You Looked, but you did not see!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Link to comment Share on other sites More sharing options...
sww Posted July 10, 2006 Author Share Posted July 10, 2006 Thanks for the comments.marfdaman: The reason I'm not using FileSelectFolder is because the folder doesn't always exist in the way that I use the app. 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