Sign in to follow this  
Followers 0

New _installfolder func code generator. Install all files and subfolders in your script.

1 post in this topic

#1 ·  Posted (edited)

Heyyy all

I read many posts asking for this. (pack whole folder into script file)

But all other code and "assist app" have problems.  Some doesn't create empty folder before install so Fileinstall() fail to run. Some doesn't include subfolders and files.

So I wrote my own one.


This code will generate a TXT file with codes and a func: _installfolder()

You can then copy the txt to the bottom of your script, and call _installfolder() once, and its all done.

The feature of this code:

1, include all files and subfolders

2, create empty subfolders before install

3, pack all lines into one func

4, easy to use. only 2 prompts asking: source root folder and destination root folder.

5, can use @tempdir @scriptdir etc in the destination folder path.

Code is here:

#cs ----------------------------------------------------------------------------
 _installfolder() Code generator
 AutoIt Version:
 Author:         KyleJustKnows

 Script Function:
    Create a TXT including the code needed to install a folder and subfolders and files into a script.

#ce ----------------------------------------------------------------------------

;create a temp folder to handle the dir > output

;asking for source and destnation folder
$sfolder=FileSelectFolder("Select source folder (As The RootFolder. All files and subfolders inside this rootfolder will be created under the target root folder later). If the folder is huge, it may take some time.","",1,@scriptdir)
$dfolder=InputBox("Target Root folder",'Type in a target root folder path (when your program running). Must be autoit text string, same as when you write a "path name" in a script. Example:   "C:\123"   (must have " ") or   @TempDir && "\123"','@ScriptDir & "\image"')
if $sfolder="" then Exit
if $dfolder="" then Exit
FileWriteLine(@tempdir&$randomtmp&'\sfolder.txt', $sfolder)
$cmd='Dir "'&$sfolder&'" /AD /B /S >> %temp%'&$randomtmp&'\sfolder.txt'
RunWait(@ComSpec & " /c " & $CMD, @WindowsDir, @SW_HIDE)
$cmd='Dir "'&$sfolder&'" /A-D /B /S > %temp%'&$randomtmp&'\sfile.txt'
RunWait(@ComSpec & " /c " & $CMD, @WindowsDir, @SW_HIDE)

;header generator , call the func and func start
FileWriteLine(@tempdir&$randomtmp&'\result.txt', "_installfolder()")
FileWriteLine(@tempdir&$randomtmp&'\result.txt', "")
FileWriteLine(@tempdir&$randomtmp&'\result.txt', "")
FileWriteLine(@tempdir&$randomtmp&'\result.txt', "Func _installfolder()")

;deal with folder
while 1   
   If @error = -1 Then ExitLoop
   $line=StringReplace($line,$sfolder,$dfolder  &  ' & "'  )
   $line="DirCreate(" & $line & '")'
   FileWriteLine(@tempdir&$randomtmp&'\result.txt', $line)

;deal with Files
while 1   
   If @error = -1 Then ExitLoop
   ;$line=StringReplace($line,$sfolder,$dfolder  &  ' & "'  )
   ;$line="DirCreate(" & $line & '")'
   $line='FileInstall("'  &  $line  &  '",'  &  StringReplace($line,$sfolder,$dfolder&' & "' )  & '",1)'
   FileWriteLine(@tempdir&$randomtmp&'\result.txt', $line)

;deal with footer
FileWriteLine(@tempdir&$randomtmp&'\result.txt', "EndFunc")

;open the result txt file
Edited by kylejustknows

Share this post

Link to post
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
Sign in to follow this  
Followers 0