WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: pguild on August 04, 2023, 10:13:28 AM

Title: Other Files When compiling
Post by: pguild on August 04, 2023, 10:13:28 AM
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
Title: Re: Other Files When compiling
Post by: td on August 04, 2023, 01:00:17 PM
Check out the compiler documentation for the settings dialog:

https://docs.winbatch.com/mergedProjects/WinBatch/WINBATCH_S__005.htm
(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 (https://docs.winbatch.com/mergedProjects/WinBatch/WINBATCH_E__003.htm)

At least one solution should become clear.
Title: Re: Other Files When compiling
Post by: pguild on August 04, 2023, 01:12:27 PM
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?
Title: ExtractAttachedFile syntax
Post by: pguild on August 04, 2023, 01:45:03 PM
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)
Title: Re: Other Files When compiling
Post by: jmburton2001 on August 05, 2023, 10:38:13 AM
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  ;)
Title: Re: Other Files When compiling
Post by: td on August 05, 2023, 05:40:06 PM
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
Title: Re: Other Files When compiling
Post by: pguild on August 05, 2023, 05:55:42 PM
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
Title: Re: Other Files When compiling
Post by: jmburton2001 on August 06, 2023, 09:15:30 AM
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.