Holger Posted February 12, 2005 Share Posted February 12, 2005 (edited) This is just a very simple example how I create my own selfextracting exe (like with IExpress) with my own inbuild-routines. It creates a second temporary au3 file with all fileinstalls of the files in a selected directory. There is no big errorhandling! Feel free to use an modify it expandcollapse popupOpt("RunErrorsFatal",0) ;Opt("TrayIconHide",1) ;#NoTrayIcon Global $tmpau3file = @TempDir & "\tocompress.au3" Global $aut2exe = "C:\Userapps\Autoit3\Aut2exe\Aut2exe.exe" Global $aut2par = " /in " & $tmpau3file & " /out " & @TempDir & "\TestArchiv.exe" & " /comp 4 /icon " & @ScriptDir & "\cab.ico" Global $filesarr[1000][3] $filesarr[0][0] = 0 Global $fileidx = 0 Global $choosefolder = FileSelectFolder("Zu komprimierender Ordner:","") ;********************************************************************* ; The standard header of the to creating temporary au3 file ;********************************************************************* Global $stdheader = "Opt(""RunErrorsFatal"",0)" & @LF & _ "Opt(""TrayIconHide"",1)" & @LF & _ "#NoTrayIcon" & @LF & _ "Global $target = """"" & @LF & _ "Global $all = 0" & @LF & _ "Global $file = """"" & @LF & _ "If $CmdLine[0] = 0 Then Exit(1)" & @LF & _ "If StringInStr($CmdLineRaw,""/t:"") Or StringInStr($CmdLineRaw,""/a"") Or StringInStr($CmdLineRaw,""/f:"") Or StringInStr($CmdLineRaw,""/h"") Or StringInStr($CmdLineRaw,""/?"") Then" & @LF & _ " For $i = 1 To $CmdLine[0]" & @LF & _ " If StringInStr($CmdLine[$i],""/t:"") Then" & @LF & _ " $target = StringTrimLeft($CmdLine[$i],3)" & @LF & _ " EndIf" & @LF & _ " If StringInStr($CmdLine[$i],""/f:"") Then" & @LF & _ " $file = StringTrimLeft($CmdLine[$i],3)" & @LF & _ " EndIf" & @LF & _ " If StringInStr($CmdLine[$i],""/a"") Then" & @LF & _ " $all = 1" & @LF & _ " EndIf" & @LF & _ " If StringInStr($CmdLine[$i],""/h"") Or StringInStr($CmdLine[$i],""/?"") Then" & @LF & _ " Msgbox(64,""SelfExtracting Parameters:"",""/a - Extract all files to a given path"" & @LF & ""/f:filename - Extract only a file with same name (NO wildcards)"" & @LF & ""/t:path - target extraction path"" & @LF & ""/h or /? - show this screen"")" & @LF & _ " Exit" & @LF & _ " EndIf" & @LF & _ " Next" & @LF & _ "Else" & @LF & _ " Exit(1)" & @LF & _ "EndIf" & @LF ;********************************************************************* ; Main program part ;********************************************************************* FilesReadToArr($choosefolder) $file = FileOpen(@TempDir & "\tocompress.au3",2) If $file <> -1 Then FileWriteLine($file,$stdheader) FileWriteLine($file,"Global $filesarr[" & $fileidx & "][3]" & @LF & @LF) For $i = 1 To $filesarr[0][0] FileWriteLine($file,"If $all Or $file = """ & $filesarr[$i][0] & """ Then" & @LF) FileWriteLine($file," If Not FileExists($target & ""\" & $filesarr[$i][1] & """) Then DirCreate($target & ""\" & $filesarr[$i][1] & """)") FileWriteLine($file," FileInstall(""" & $choosefolder & "\" & $filesarr[$i][1] & "\" & $filesarr[$i][0] & """,$target & ""\" & $filesarr[$i][1] & "\" & $filesarr[$i][0] & """,1)") FileWriteLine($file,"EndIf" & @LF) Next FileClose($file) EndIf ; Now compress the created au3 file to the selfextracting exe RunWait($aut2exe & $aut2par,"",@SW_HIDE) FileDelete($tmpau3file) Exit ;********************************************************************* ; Read the file tree and save the path/subfolder/filename to an array ;********************************************************************* Func FilesReadToArr($path) Local $path,$idx,$search,$info,$file,$folder $search = FileFindFirstFile($path & "\*.*") If $search <> -1 Then While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file <> "." And $file <> ".." Then If StringInStr(FileGetAttrib($path & "\" & $file),"D") Then FilesReadToArr($path & "\" & $file) Else $info = StringReplace($path & "\" & $file,$choosefolder,"") $folder = StringTrimLeft(StringReplace($path,$choosefolder,""),1) If StringInStr($info,"\",0,-1) > 1 Then $singlefile = StringTrimLeft($info,StringLen($folder) + 1) Else $singlefile = $info EndIf $singlefile = StringTrimLeft($singlefile,1) $fileidx = $fileidx + 1 $filesarr[0][0] = $fileidx $filesarr[$fileidx][0] = $singlefile $filesarr[$fileidx][1] = $folder $filesarr[$fileidx][2] = $path & "\" & $file EndIf EndIf WEnd FileClose($search) EndIf EndFunc Regards Holger Edited February 12, 2005 by Holger Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView Link to comment Share on other sites More sharing options...
DirtyBanditos Posted February 13, 2005 Share Posted February 13, 2005 This is just a very simple example how I create my own selfextracting exe (like with IExpress) with my own inbuild-routines.It creates a second temporary au3 file with all fileinstalls of the files in a selected directory.There is no big errorhandling!Feel free to use an modify it expandcollapse popupOpt("RunErrorsFatal",0) ;Opt("TrayIconHide",1) ;#NoTrayIcon Global $tmpau3file = @TempDir & "\tocompress.au3" Global $aut2exe = "C:\Userapps\Autoit3\Aut2exe\Aut2exe.exe" Global $aut2par = " /in " & $tmpau3file & " /out " & @TempDir & "\TestArchiv.exe" & " /comp 4 /icon " & @ScriptDir & "\cab.ico" Global $filesarr[1000][3] $filesarr[0][0] = 0 Global $fileidx = 0 Global $choosefolder = FileSelectFolder("Zu komprimierender Ordner:","") ;********************************************************************* ; The standard header of the to creating temporary au3 file ;********************************************************************* Global $stdheader = "Opt(""RunErrorsFatal"",0)" & @LF & _ "Opt(""TrayIconHide"",1)" & @LF & _ "#NoTrayIcon" & @LF & _ "Global $target = """"" & @LF & _ "Global $all = 0" & @LF & _ "Global $file = """"" & @LF & _ "If $CmdLine[0] = 0 Then Exit(1)" & @LF & _ "If StringInStr($CmdLineRaw,""/t:"") Or StringInStr($CmdLineRaw,""/a"") Or StringInStr($CmdLineRaw,""/f:"") Or StringInStr($CmdLineRaw,""/h"") Or StringInStr($CmdLineRaw,""/?"") Then" & @LF & _ " For $i = 1 To $CmdLine[0]" & @LF & _ " If StringInStr($CmdLine[$i],""/t:"") Then" & @LF & _ " $target = StringTrimLeft($CmdLine[$i],3)" & @LF & _ " EndIf" & @LF & _ " If StringInStr($CmdLine[$i],""/f:"") Then" & @LF & _ " $file = StringTrimLeft($CmdLine[$i],3)" & @LF & _ " EndIf" & @LF & _ " If StringInStr($CmdLine[$i],""/a"") Then" & @LF & _ " $all = 1" & @LF & _ " EndIf" & @LF & _ " If StringInStr($CmdLine[$i],""/h"") Or StringInStr($CmdLine[$i],""/?"") Then" & @LF & _ " Msgbox(64,""SelfExtracting Parameters:"",""/a - Extract all files to a given path"" & @LF & ""/f:filename - Extract only a file with same name (NO wildcards)"" & @LF & ""/t:path - target extraction path"" & @LF & ""/h or /? - show this screen"")" & @LF & _ " Exit" & @LF & _ " EndIf" & @LF & _ " Next" & @LF & _ "Else" & @LF & _ " Exit(1)" & @LF & _ "EndIf" & @LF ;********************************************************************* ; Main program part ;********************************************************************* FilesReadToArr($choosefolder) $file = FileOpen(@TempDir & "\tocompress.au3",2) If $file <> -1 Then FileWriteLine($file,$stdheader) FileWriteLine($file,"Global $filesarr[" & $fileidx & "][3]" & @LF & @LF) For $i = 1 To $filesarr[0][0] FileWriteLine($file,"If $all Or $file = """ & $filesarr[$i][0] & """ Then" & @LF) FileWriteLine($file," If Not FileExists($target & ""\" & $filesarr[$i][1] & """) Then DirCreate($target & ""\" & $filesarr[$i][1] & """)") FileWriteLine($file," FileInstall(""" & $choosefolder & "\" & $filesarr[$i][1] & "\" & $filesarr[$i][0] & """,$target & ""\" & $filesarr[$i][1] & "\" & $filesarr[$i][0] & """,1)") FileWriteLine($file,"EndIf" & @LF) Next FileClose($file) EndIf ; Now compress the created au3 file to the selfextracting exe RunWait($aut2exe & $aut2par,"",@SW_HIDE) FileDelete($tmpau3file) Exit ;********************************************************************* ; Read the file tree and save the path/subfolder/filename to an array ;********************************************************************* Func FilesReadToArr($path) Local $path,$idx,$search,$info,$file,$folder $search = FileFindFirstFile($path & "\*.*") If $search <> -1 Then While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file <> "." And $file <> ".." Then If StringInStr(FileGetAttrib($path & "\" & $file),"D") Then FilesReadToArr($path & "\" & $file) Else $info = StringReplace($path & "\" & $file,$choosefolder,"") $folder = StringTrimLeft(StringReplace($path,$choosefolder,""),1) If StringInStr($info,"\",0,-1) > 1 Then $singlefile = StringTrimLeft($info,StringLen($folder) + 1) Else $singlefile = $info EndIf $singlefile = StringTrimLeft($singlefile,1) $fileidx = $fileidx + 1 $filesarr[0][0] = $fileidx $filesarr[$fileidx][0] = $singlefile $filesarr[$fileidx][1] = $folder $filesarr[$fileidx][2] = $path & "\" & $file EndIf EndIf WEnd FileClose($search) EndIf EndFuncRegards Holger <{POST_SNAPBACK}>Hi Holger Thx you looks great i will test it out) Link to comment Share on other sites More sharing options...
sabine-uwe Posted July 22, 2005 Share Posted July 22, 2005 Hello HolgerThanks for this script.I used the idea and structure to build a script that reads all information in one array:choose a start-folder an you will get an array with - all files of this folder, - the number of subfolders and - the number of files in this array -> and this also for every subfolderMy Post : read files + foldes + subfolders into arrayMaybe somebody else can use it.Maybe it can also help for the "TreeView browsing"-Project ? RegardsUweP.S.: By the way: thanks for your great work !! 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