You are here

Cleaning up after program opens file

5 posts / 0 new
Last post
terra666
Offline
Last seen: 3 years 11 months ago
Joined: 2014-06-22 13:42
Cleaning up after program opens file

Hi,
I am trying to portablize a program. Everything is working fine, but for one thing. The program creates a file in the directory it opens a file from. So, lets say I open folder1\blah.ext the program will create "file.ext" in that folder. If I open a new file in let's say folder2\blahblah.ext it will create a new "file.ext" in that directory as well.
My question is how can I clean up those files on the exit of the program.
Thank you for the help.

Ken Herbert
Ken Herbert's picture
Offline
Last seen: 1 hour 37 min ago
DeveloperModerator
Joined: 2010-05-25 18:19
As far as I know, you can't

There is no way to do this with the PortableApps Launcher.

There may possibly be ways to do it with custom code, but I know very little NSIS and it sounds like it would fall in the range of complex to impossible, since you would have to hook into filesystem calls, determine which files were accessed (or created?) only by your program, record them somewhere, then clean them up on an exit hook.

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 1 month 3 weeks ago
DeveloperModerator
Joined: 2008-07-24 18:46
Agreed

I agree, this would have to be something you're doing while the app is running, not on close or start, which would be very messy to program using NSIS.

This seems like a very sloppy way of operating a program - what application is it that does this?

terra666
Offline
Last seen: 3 years 11 months ago
Joined: 2014-06-22 13:42
Hi, The app saves the last

Hi,
The app saves the last four open files in registry. Is it possible to continuously read off a registry key while the program is running and record which folders the files are in.
Then the program can go down the list and remove the file from those folders.

Gord Caswell
Gord Caswell's picture
Offline
Last seen: 1 month 3 weeks ago
DeveloperModerator
Joined: 2008-07-24 18:46
Not easily

If the application only stores the last four files, then not easily, no. If it was all recent files, it'd be easy to do (simply read the relevant registry key on close and delete the file in those locations), but not only the last four. PAL is unable to do a continuous action while a program is running as it simply runs ExecWait on the main application's exe after doing the start-up magic, and cleans up afterwards.

Again, which program is it? Maybe we can figure out another way to solve the problem if we can check it out ourselves as well.

Log in or register to post comments