FireFox Posted March 8, 2009 Share Posted March 8, 2009 (edited) Hi, I've made a FileInstallFolder function, wich use variables for install any file found in this folder ... From help file : The source path of the file to compile. This must be a literal string; it cannot be a variable. Here is my UDF : expandcollapse popup; #FUNCTION# ;=============================================================================== ; ; Name...........: _FileInstallFolder ; Description ...: Install file(s) from a folder ; Syntax.........: _FileInstallFolder($sSource, $sDest, $nFlag = 1, $sCompiled = False) ; Parameters ....: $sSource = Source folder to get file(s) from ; $sDest = Destination to install file(s) to ; $nFlag = According to the flag of FileInstall ; $sCompiled - One of the following: ; False = Always install file(s) ; True = Only install file(s) when the script is compiled ; Return values .: Success - Returns 1 ; Failure - Returns 0 ; Author ........: FireFox ; Modified.......: ; Remarks .......: this function is faster with _WinAPI_FileFind : ; http://www.autoitscript.com/forum/index.php?showtopic=90545 ; Related .......: ; Link ..........; ; Example .......; ; ; ;========================================================================================== Func _FileInstallFolder($sSource, $sDest, $nFlag = 1, $sCompiled = False) Local $sFile, $sNext, $sDir If Not $sCompiled Then $sFile = FileFindFirstFile($sSource) While 1 $sNext = FileFindNextFile($sFile) If @error Then ExitLoop ;No more files $sDir = StringRegExpReplace($sSource, '^.*\\', '') If @error Then Return SetError(1, 0, 0) If Not FileExists($sDir) Then DirCreate($sDir) If @error Then Return SetError(2, 0, 0) FileInstall($sNext, $sDest & '\' & $sDir & '\' & $sNext, $nFlag) If @error Then Return SetError(3, 0, 0) WEnd ElseIf $sCompiled And @Compiled Then $sFile = FileFindFirstFile($sSource) While 1 $sNext = FileFindNextFile($sFile) If @error Then ExitLoop ;No more files $sDir = StringRegExpReplace($sSource, '^.*\\', '') If @error Then Return SetError(1, 0, 0) If Not FileExists($sDir) Then DirCreate($sDir) If @error Then Return SetError(2, 0, 0) FileInstall($sNext, $sDest & '\' & $sDir & '\' & $sNext, $nFlag) If @error Then Return SetError(3, 0, 0) WEnd EndIf Return 1 EndFunc ;==>_FileInstallFolder I need remake to make i work with my "valid" variables, in the way I prefer to use this function instead of write a thousand lines of FileInstall ! Cheers, FireFox. Edited March 8, 2009 by FireFox Link to comment Share on other sites More sharing options...
Bowmore Posted March 8, 2009 Share Posted March 8, 2009 Thats just not going to work. FileInstall will never accept a variable as the source. There are two options open to you that I can see. 1 Put all your files in a zip file and use that with FileInstall(). When its installed have your script unzip it. 2 Write a seperate script, possibly using a modified version of you FileInstallFolder function to write a block of valid FileInstall() statments to the console or a text file from which you can cut and paste into your main script. "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
martin Posted March 8, 2009 Share Posted March 8, 2009 Hi, I've made a FileInstallFolder function, wich use variables for install any file found in this folder ... From help file : Here is my UDF : expandcollapse popup; #FUNCTION# ;=============================================================================== ; ; Name...........: _FileInstallFolder ; Description ...: Install file(s) from a folder ; Syntax.........: _FileInstallFolder($sSource, $sDest, $nFlag = 1, $sCompiled = False) ; Parameters ....: $sSource = Source folder to get file(s) from ; $sDest = Destination to install file(s) to ; $nFlag = According to the flag of FileInstall ; $sCompiled - One of the following: ; False = Always install file(s) ; True = Only install file(s) when the script is compiled ; Return values .: Success - Returns 1 ; Failure - Returns 0 ; Author ........: FireFox ; Modified.......: ; Remarks .......: this function is faster with _WinAPI_FileFind : ; http://www.autoitscript.com/forum/index.php?showtopic=90545 ; Related .......: ; Link ..........; ; Example .......; ; ; ;========================================================================================== Func _FileInstallFolder($sSource, $sDest, $nFlag = 1, $sCompiled = False) Local $sFile, $sNext, $sDir If Not $sCompiled Then $sFile = FileFindFirstFile($sSource) While 1 $sNext = FileFindNextFile($sFile) If @error Then ExitLoop ;No more files $sDir = StringRegExpReplace($sSource, '^.*\\', '') If @error Then Return SetError(1, 0, 0) If Not FileExists($sDir) Then DirCreate($sDir) If @error Then Return SetError(2, 0, 0) FileInstall($sNext, $sDest & '\' & $sDir & '\' & $sNext, $nFlag) If @error Then Return SetError(3, 0, 0) WEnd ElseIf $sCompiled And @Compiled Then $sFile = FileFindFirstFile($sSource) While 1 $sNext = FileFindNextFile($sFile) If @error Then ExitLoop ;No more files $sDir = StringRegExpReplace($sSource, '^.*\\', '') If @error Then Return SetError(1, 0, 0) If Not FileExists($sDir) Then DirCreate($sDir) If @error Then Return SetError(2, 0, 0) FileInstall($sNext, $sDest & '\' & $sDir & '\' & $sNext, $nFlag) If @error Then Return SetError(3, 0, 0) WEnd EndIf Return 1 EndFunc ;==>_FileInstallFolder I need remake to make i work with my "valid" variables, in the way I prefer to use this function instead of write a thousand lines of FileInstall ! Cheers, FireFox.The reason you can't have variables in FileInstall is that the files have to be included before the script runs so there is no way it can know what to install. So you could do something like this remove the present function from your script and add this line to the top #include "fiScript.au3" Save the modified function below to a file called fiScript.au3 Func _FileInstallFolder($sSource, $sDest, $nFlag = 1, $sCompiled = False) Local $sFile, $sNext, $sDir Local $FI_Include = FileOpen("ficompile.au3",2) FileWriteLine($FI_Include,"Func _FileInstallFolder($sSource, $sDest, $nFlag = 1, $sCompiled = False)") If Not $sCompiled Then $sFile = FileFindFirstFile($sSource) While 1 $sNext = FileFindNextFile($sFile) If @error Then ExitLoop;No more files $sDir = StringRegExpReplace($sSource, '^.*\\', '') If @error Then Return SetError(1, 0, 0) If Not FileExists($sDir) Then DirCreate($sDir) If @error Then Return SetError(2, 0, 0) FileInstall($sNext, $sDest & '\' & $sDir & '\' & $sNext, $nFlag) If @error Then Return SetError(3, 0, 0) WEnd ElseIf $sCompiled And @Compiled Then $sFile = FileFindFirstFile($sSource) While 1 $sNext = FileFindNextFile($sFile) If @error Then ExitLoop;No more files $sDir = StringRegExpReplace($sSource, '^.*\\', '') If @error Then Return SetError(1, 0, 0) If Not FileExists($sDir) Then DirCreate($sDir) If @error Then Return SetError(2, 0, 0) FileWriteLine($FI_Include,"FileInstall(" & $sNext & ',' & $sDest & '\' & $sDir & '\' & $sNext & ',' & $nFlag & ')') ;FileInstall($sNext, $sDest & '\' & $sDir & '\' & $sNext, $nFlag) If @error Then Return SetError(3, 0, 0) WEnd EndIf FileWriteLine($FI_Include,"EndFunc") FileClose($FI_Include) Return 1 EndFunc ;==>_FileInstallFolder Now when you run it from SciTE say it will behave as before except that it creates a file called ficompile .au3 To compile the script replace the line #include "fiScript.au3" with #include "ficompile.au3" Not tested, just an idea. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 8, 2009 Share Posted March 8, 2009 Why do so many people not understand why it can't take variables? Link to comment Share on other sites More sharing options...
MrCreatoR Posted March 8, 2009 Share Posted March 8, 2009 The second option $sRet_FI_Lines = _FileInstallGetFolder("C:\Temp", "C:\Dest", 0, "*.txt") ConsoleWrite("+Return:" & @CRLF & $sRet_FI_Lines & @CRLF & @CRLF & "!Error = " & @error & @CRLF) Func _FileInstallGetFolder($sSource, $sDest, $nFlag = 0, $sMask = "*", $sCompiled = False) Local $hSearch, $sNext_File, $sRet_FI_Lines = "" If (Not $sCompiled) Or ($sCompiled And @Compiled) Then $hSearch = FileFindFirstFile($sSource & "\" & $sMask) If $hSearch = -1 Then Return SetError(1, 0, "") While 1 $sNext_File = FileFindNextFile($hSearch) If @error Then ExitLoop ;No more files $sRet_FI_Lines &= _ 'FileInstall("' & $sSource & '\' & $sNext_File & '", "' & $sDest & '\' & $sNext_File & '", ' & $nFlag & ')' & @CRLF WEnd FileClose($hSearch) EndIf If $sRet_FI_Lines = "" Then Return SetError(2, 0, "") Return StringStripWS($sRet_FI_Lines, 3) EndFunc  Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1  AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ==================================================    AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
FireFox Posted March 8, 2009 Author Share Posted March 8, 2009 @Everybody Thanks for all your help @MrCreator Thanks, I thought to make it in that way @Richard Robertson Hahaha....I understand, just needed remake or another way Cheers, FireFox. Link to comment Share on other sites More sharing options...
Richard Robertson Posted March 8, 2009 Share Posted March 8, 2009 You'll have to have all of the files ready before the script is compiled. There's no getting around that. Link to comment Share on other sites More sharing options...
FireFox Posted March 8, 2009 Author Share Posted March 8, 2009 its not about that... all files are ready :I prefer to use this function instead of write a thousand lines of FileInstall !Cheers, Firefox. Link to comment Share on other sites More sharing options...
martin Posted March 8, 2009 Share Posted March 8, 2009 Why do so many people not understand why it can't take variables??There were 2 replies up to that post and neither one suggested FileInstall could use variables so I don't understand the point of your post. Added to that the OP was asking how to get round it so he uderrstood that FileInstall can't use variables. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
trancexx Posted March 8, 2009 Share Posted March 8, 2009 martin Hood ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
FireFox Posted March 8, 2009 Author Share Posted March 8, 2009 (edited) @martinthanks to agree with me about this @EveryoneFinally I found a nice way to do it with MrCreator suggestion !Here is the UDF :expandcollapse popup; #FUNCTION# ;=================================================================================================== ==================================== ; ; Name...........: _ListFileInstallFolder ; Description ...: List Install file(s) from a folder into au3 ; Syntax.........: _ListFileInstallFolder($sSource, $sDest, $nFlag = 0, $sMask = '*', $sName = 'include', $sOverWrite = False, $sCompiled = False) ; Parameters ....: $sSource = Source folder to get file(s) from ; $sDest = Destination to install file(s) to ; $nFlag = According to the flag of FileInstall [Optional] ; $sMask = Extensions of file(s) to List [Optional] ; $sName = Out au3 script name [Optional] ; $sCompiled - One of the following: [Optional] ; False = Always install file(s) ; True = Only install file(s) when the script is compiled ; Return values .: Success - Returns 1 ; Failure - Returns 0 ; Author ........: MrCreator, FireFox ; Modified.......: FireFox ; Remarks .......: this function is faster with _WinAPI_FileFind : ; [url="http://www.autoitscript.com/forum/index.php?showtopic=90545"]http://www.autoitscript.com/forum/index.php?showtopic=90545[/url] ; Related .......: ; Link ..........; ; Example .......; ; ; ;=================================================================================================== =============================================== Func _ListFileInstallFolder($sSource, $sDest, $nFlag = 0, $sMask = '*', $sName = 'include', $sOverWrite = False, $sCompiled = False) Local $hSearch, $sNext_File, $sRet_FI_Lines = '' If (Not $sCompiled) Or ($sCompiled And @Compiled) Then $hSearch = FileFindFirstFile($sSource & '\' & $sMask) If $hSearch = -1 Then Return SetError(1, 0, 'FileFindFirstFile') While 1 $sNext_File = FileFindNextFile($hSearch) If @error Then ExitLoop ;No more files $sRet_FI_Lines &= @CRLF & _ 'FileInstall("' & $sSource & '\' & $sNext_File & '", "' & $sDest & '\' & $sNext_File & '", ' & $nFlag & ')' WEnd FileClose($hSearch) EndIf If $sRet_FI_Lines = '' Then Return SetError(2, 0, '') If $sOverWrite Then FileDelete(@ScriptDir & '\' & $sName & '.au3') Return FileWrite(@ScriptDir & '\' & $sName & '.au3', StringStripWS($sRet_FI_Lines, 3)) EndFunc ;==>_ListFileInstallFolderCheers, FireFox. Edited March 8, 2009 by FireFox Link to comment Share on other sites More sharing options...
ProgAndy Posted March 8, 2009 Share Posted March 8, 2009 I have an idea Why not create an Au3Wrapperdirective to create that automatically. Then use an exe in runbefore which reads it and creates the include-file just before compiling and includes the #includeline if it doesn't already exists. *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
FireFox Posted March 8, 2009 Author Share Posted March 8, 2009 @ProgAndySeems to be a good idea Why not create an Au3Wrapperdirective to create that automaticallyIn english please (Can you explain me how to do it ?)Cheers, FireFox. Link to comment Share on other sites More sharing options...
ProgAndy Posted March 10, 2009 Share Posted March 10, 2009 (edited) Here, an example-script. You have to add the code for generating FileInstalls / DirCreates. expandcollapse popup; Use this to run the exe: ; #AutoIt3Wrapper_Run_Before=FolderIncluder.exe "%scriptfile%" "%in%" "%scriptdir%" ; Syntax for includes: ; #FolderInclude=^^Folder from^^ PIPE ^^Folder To (AutoIt syntax)^^ PIPE ^^FileInstallFalgs^^ PIPE ^^Only Install on compile^^ ; Example ; #FolderInclude=C:\Folder\From| @ScriptDir & "\test"|0|1 ; There is also #FolderInclude_Recurse for recursive including (not impemented yet ; Author: Prog@ndy If $CMDLINE[0] <> 3 Then Exit $ScriptFullPath= $CMDLINE[2] $ScriptNameNoExt = $CMDLINE[1] $ScriptDir = $CMDLINE[3] $File = FileRead($ScriptFullPath) Global Const $FolderIncludeFile = $ScriptDir & "\" & $ScriptNameNoExt & ".folders.inc.au3" FileDelete($FolderIncludeFile) Global $InstallFileString = ";###############################################################" & @CRLF $InstallFileString &= ";## File is generated automatically ##"& @CRLF $InstallFileString &= ";###############################################################"& @CRLF $InstallFileString &= "#include-once" & @CRLF &@CRLF FileInstall $directives = StringRegExp($File, "(?:\A|\n)\s*#FolderInclude\h*=([^;]+)", 1) If Not @error Then For $i = 0 To UBound($directives) $FolderInfo = StringSplit($directives[$i],"|") If $FolderInfo[0] <> 4 Then ConsoleWrite("! Wrong formatted: #FolderInclude=" & $directives[$i] & @CRLF) $FolderFrom = StringStripWS($FolderInfo[1],3) $FolderTo = StringStripWS($FolderInfo[2],3) $FolderFlags = StringStripWS($FolderInfo[3],3) $FolderOnlyCompiled = __IsTrue(StringStripWS($FolderInfo[4],3)) If $FolderOnlyCompiled Then $InstallFileString &= @CRLF & "If @Compiled Then" & @CRLF ; Find files in FolderFrom ; create FileInstalls: MsgBox(0, '', "Here goes a filefind-loop for files (FileInstall) and Folders (DirCreate)") ;$InstallFileString &= 'FileInstall("' & $sSource & '\' & $sNext_File & '", "' & $sDest & '\' & $sNext_File & '", ' & $nFlag & ')' If $FolderOnlyCompiled Then $InstallFileString &= "EndIf ; @Comiled" & @CRLF & @CRLF Next EndIf $directives_Rec = StringRegExp($File, "\n\s*#FolderInclude_Recurse\h*=([^;]+)", 1) If Not @error Then MsgBox(0, '', "The same as above, but recursive") EndIf ; Prog@ndy Func __IsTrue($String) $String = StringStripWS($String, 8) Return ($String = "true") Or (Number($String)>0) Or ($String = "yes") EndFunc Edited March 10, 2009 by ProgAndy *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Spiff59 Posted March 10, 2009 Share Posted March 10, 2009 (edited) Why live with the requirement to have a static file list defined prior to compiling the script? Why not have a "build" script that: 1. Dynamically generates a second temporary .au3 source containing your main script and FileInstall names embedded. 2. Submits the temp script for compilation 3. Deletes the temporary source file That ought to dynamically pick up whatever files exist in your specified directory at runtime and build you an up-to-date executable with those files "installed", all without any user intervention??? Edit: clarified original post. (this may be similar in concept to what ProgAndy is proposing?) Edited March 11, 2009 by Spiff59 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