| View previous topic :: View next topic |
| Author |
Message |
socom1880
Joined: 14 Aug 2008 Posts: 34
|
Posted: Mon Aug 18, 2008 6:34 pm Post subject: deleting a file anywhere |
|
|
is there a way to delete a file that is anywhere on a computer? for example, if i install a .exe file on another computer, and, when i first run it, i want it to automatically delete the setup file i used to create it. i tried doing
FileDelete, C:\*\*\Setup.exe
but that didnt work. is there a way to make this work without knowing the specific place the file is saved to? |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Mon Aug 18, 2008 6:38 pm Post subject: |
|
|
How about....
| Code: |
Loop, C:\Setup.exe, 0, 1 ;the final 1 makes it recurse into subfolders
FileDelete, %A_LoopFileLongPath% |
Not tested, you might want to try it out with a MsgBox or something first rather than running the risk of it accidentally deleting something. |
|
| Back to top |
|
 |
Razlin
Joined: 05 Nov 2007 Posts: 434 Location: canada
|
Posted: Mon Aug 18, 2008 6:43 pm Post subject: |
|
|
| Code: | | FileDelete, Setup.exe |
Should delete if its in the same folder as the program calling it.
read filedelete in help.
I would also be testing it with asdfasdf.exe first.
You dont want to c:\*\*\setup.exe that would be REALLLLLLY BAD if it would work as it would delete ALLLL setup files on your machine that are within 2 folders.. *\*\ _________________ -=Raz=- |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Mon Aug 18, 2008 6:48 pm Post subject: Re: deleting a file anywhere |
|
|
@ Razlin -
| Quote: | | You dont want to c:\*\*\setup.exe that would be REALLLLLLY BAD if it would work as it would delete ALLLL setup files on your machine that are within 2 folders.. *\*\ |
Are you sure about that?:
| socom1880 wrote: | | is there a way to delete a file that is anywhere on a computer? |
Hopefully he would mainly be using filenames that are a little less common, so that he wouldn't delete anything important.. |
|
| Back to top |
|
 |
socom1880
Joined: 14 Aug 2008 Posts: 34
|
Posted: Mon Aug 18, 2008 6:50 pm Post subject: |
|
|
| yeah the setup name wouldnt be setup. it would be something like myprogramsetup.exe |
|
| Back to top |
|
 |
socom1880
Joined: 14 Aug 2008 Posts: 34
|
Posted: Mon Aug 18, 2008 7:04 pm Post subject: |
|
|
ok so using this
FileDelete, Setup.exe
just doesnt seem to work at all
Loop, C:\Setup.exe, 0, 1 ;the final 1 makes it recurse into subfolders
FileDelete, %A_LoopFileLongPath%
this worked once but then the next time i tried it, it lagged to computer so i had to restart |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Mon Aug 18, 2008 7:12 pm Post subject: |
|
|
Hmm... Actually, I'm not sure how to deal with that. You could add sleep within the Loop, but the loop should only be activated once—when the file is found. Perhaps changing the SetBatchLines value higher could help. Also, you can add a break once the file has been found:
| Code: | Loop, C:\Setup.exe, 0, 1 ;the final 1 makes it recurse into subfolders
{
FileDelete, %A_LoopFileLongPath%
Break
} |
|
|
| Back to top |
|
 |
socom1880
Joined: 14 Aug 2008 Posts: 34
|
Posted: Mon Aug 18, 2008 7:20 pm Post subject: |
|
|
| ok lol i tried it again (not with ur new script) and it lagged for a bit then it said it was done but the file was still there |
|
| Back to top |
|
 |
Razlin
Joined: 05 Nov 2007 Posts: 434 Location: canada
|
Posted: Tue Aug 19, 2008 12:50 pm Post subject: |
|
|
I believe socom is trying to make an installer that deletes itself when its completed. hence delete anywhere.. meaning he wants it to delete itself no matter where the user saves his/her file.
The reason your having a hard time deleting with
| Code: | | FileDelete, Setup.exe |
As I had mentionned, is more then likely because you are calling it while the program is "active/running" and therefore windows is getting an access denied on the file.
If this is what your trying to do you can write a batch file to delete it when your program exits
Here is an example from engunneer at this post
http://www.autohotkey.com/forum/viewtopic.php?t=20962
| Code: | FileAppend,
(
dir c:\windows\System32 /b /s
del "%A_SCRIPTFULLPATH%"
del c:\temp.bat
), c:\temp.bat
sleep, 1000
Run, %COMSPEC% /c c:\temp.bat,,hide
ExitApp
|
_________________ -=Raz=- |
|
| Back to top |
|
 |
socom1880
Joined: 14 Aug 2008 Posts: 34
|
Posted: Tue Aug 19, 2008 5:35 pm Post subject: |
|
|
| yeah thats exatcly wat im trying to do. do u no if there is a way to make the installer just delete after it is done (probably not done with autohotkey). if not, for the code u just gave me, how would i specify the file name that it is deleting? |
|
| Back to top |
|
 |
Razlin
Joined: 05 Nov 2007 Posts: 434 Location: canada
|
Posted: Tue Aug 19, 2008 5:41 pm Post subject: |
|
|
| Code: | FileAppend,
(
dir c:\windows\System32 /b /s
del "%A_SCRIPTFULLPATH%" ;<<<< Is the name of your script. its a built in variable
del c:\temp.bat
), c:\temp.bat
sleep, 1000
Run, %COMSPEC% /c c:\temp.bat,,hide
ExitApp |
_________________ -=Raz=- |
|
| Back to top |
|
 |
socom1880
Joined: 14 Aug 2008 Posts: 34
|
Posted: Tue Aug 19, 2008 5:44 pm Post subject: |
|
|
| wait but then wouldnt that delete the autohotkey script, not the install file? |
|
| Back to top |
|
 |
Sivvy
Joined: 21 Jul 2008 Posts: 711 Location: Calgary, AB, Canada
|
Posted: Tue Aug 19, 2008 5:46 pm Post subject: |
|
|
| It would delete the script currently running. |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1145 Location: The Interwebs
|
Posted: Tue Aug 19, 2008 6:04 pm Post subject: |
|
|
| I believe he wants to delete an existing installer (not made in AHK), not make an installer that can delete itself. |
|
| Back to top |
|
 |
socom1880
Joined: 14 Aug 2008 Posts: 34
|
Posted: Tue Aug 19, 2008 11:35 pm Post subject: |
|
|
| wat i want to do is to make the installer (that is used to create an autohotkey .exe file) automatically delete once it has been installed. right now, i just made the script force them to find the correct setup file so it can delete it before the program can run. id really like it if the setup file just deleted once it successfully installed |
|
| Back to top |
|
 |
|