Other Files When compiling

Started by pguild, August 04, 2023, 10:13:28 AM

Previous topic - Next topic

pguild

My application requires various .txt files to be in the same folder as the .exe file.  I used to supply a zip file to the user and they were instructed to unzip the files. This worked, but it was a bit difficult for some users. So I started putting the .txt files into the OTHER FILES section when compiling the Winbatch Script.

My intent is to allow users to modify some of these .txt files. But it seems that each time the user activates the application, those .txt files overwrite any changes that have been made to the .txt files. Correct?  If this is the case then I need a different method for supplying the .txt files to the user.

Any suggestions?  Thanks.
Phil Seyer
www.DogTrainingPsychology.com -- "Don't wish it were easier, wish you were better."  as aphorism by Jim Rohn as quoted in the Kindle Book, GEMS OF WISDOM by Philip Seyer

td

Check out the compiler documentation for the settings dialog:

https://docs.winbatch.com/mergedProjects/WinBatch/WINBATCH_S__005.htm

Note the "Skip auto-extraction of "Extender" and "Other Files" option.

Then check out the documentation for the compiler function ExtractAttachedFile:

https://docs.winbatch.com/mergedProjects/WinBatch/WINBATCH_E__003.htm

At least one solution should become clear.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

pguild

Thanks!
I want "other files" to be extracted only the first time the user starts up the .exe by double-clicking on it.
Is there an option for that?  What does "skip auto-extraction of other files mean?
www.DogTrainingPsychology.com -- "Don't wish it were easier, wish you were better."  as aphorism by Jim Rohn as quoted in the Kindle Book, GEMS OF WISDOM by Philip Seyer

pguild

Would this be the correct code for extracting the other files, where the compiled exe is called "Test.exe"  (Thanks!)

rc = ExtractAttachedFile("Test.exe",2)

No it is not correct as I discovered after making this post. Just put the filename of the file you want to be extracted.  For example,
if you want to extract a file called "hello.txt" -- use this code:

rc = ExtractAttachedFile("hello.txt,2)
www.DogTrainingPsychology.com -- "Don't wish it were easier, wish you were better."  as aphorism by Jim Rohn as quoted in the Kindle Book, GEMS OF WISDOM by Philip Seyer

jmburton2001

I struggled with this (have a text file that could be updated) a few years ago and I came up with a solution that worked for me.

I tried the "Other Files" options and found that every time my compiled script was executed it overwrote the text file. Here's what I ended up doing because my text files started out pretty small and would grow over time as users updated them.

Instead of extracting the text file I'd have my script check for its existence (FileExist). If it didn't exist I'd have my script create it (FileOpen, FileWrite, FileClose). If the file existed, then I'd do a simple "GoTo" the next section of my script to skip the creation.

Even if a user went into the script directory (defined with DirScript) and deleted or renamed the text file, on the next execution it would create the file using my default contents.

I found that doing it on the fly like this didn't affect the execution times since text files are pretty trivial to create.

YMMV  ;)

td

A very basic example:
Code (winbatch) Select
files[0] = "Stuff.txt"
files[1] = "MoreStuff.txt"

foreach file in files
   if FileExist(file) then continue
   ExtractAttachedFile(file, file)
next

exit
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

pguild

Thank you this looks very elegant.
But I don't understand this.  Why is "file" repeated in the line and use for both the first and second argument?
   ExtractAttachedFile(file, file)

foreach file in files
   if FileExist(file) then continue
   ExtractAttachedFile(file, file)
next
www.DogTrainingPsychology.com -- "Don't wish it were easier, wish you were better."  as aphorism by Jim Rohn as quoted in the Kindle Book, GEMS OF WISDOM by Philip Seyer

jmburton2001

Quote from: pguild on August 05, 2023, 05:55:42 PM
Why is "file" repeated in the line and use for both the first and second argument?
   ExtractAttachedFile(file, file)

Look up "ExtractAttachedFile" in the consolidated WIL help file. The variable "file" is included twice because of the syntax:

ExtractAttachedFile (source-name, target-name) {compiled version only}

The help file has additional guidance.

You can also search the Tech Database for "ExtractAttachedFile" for additional samples and guidance.