Author Topic: Other Files When compiling  (Read 602 times)

pguild

  • Jr. Member
  • **
  • Posts: 88
  • The dog is always right!
    • MasteryLearning
Other Files When compiling
« 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

td

  • Tech Support
  • *****
  • Posts: 4444
    • WinBatch
Re: Other Files When compiling
« Reply #1 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

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

  • Jr. Member
  • **
  • Posts: 88
  • The dog is always right!
    • MasteryLearning
Re: Other Files When compiling
« Reply #2 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?

pguild

  • Jr. Member
  • **
  • Posts: 88
  • The dog is always right!
    • MasteryLearning
ExtractAttachedFile syntax
« Reply #3 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)

jmburton2001

  • Full Member
  • ***
  • Posts: 136
Re: Other Files When compiling
« Reply #4 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  ;)

td

  • Tech Support
  • *****
  • Posts: 4444
    • WinBatch
Re: Other Files When compiling
« Reply #5 on: August 05, 2023, 05:40:06 pm »
A very basic example:
Code: Winbatch
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

  • Jr. Member
  • **
  • Posts: 88
  • The dog is always right!
    • MasteryLearning
Re: Other Files When compiling
« Reply #6 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

jmburton2001

  • Full Member
  • ***
  • Posts: 136
Re: Other Files When compiling
« Reply #7 on: August 06, 2023, 09:15:30 am »
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.