AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

deleting a file anywhere
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
socom1880



Joined: 14 Aug 2008
Posts: 34

PostPosted: Mon Aug 18, 2008 6:34 pm    Post subject: deleting a file anywhere Reply with quote

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
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Mon Aug 18, 2008 6:38 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
Razlin



Joined: 05 Nov 2007
Posts: 434
Location: canada

PostPosted: Mon Aug 18, 2008 6:43 pm    Post subject: Reply with quote

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
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Mon Aug 18, 2008 6:48 pm    Post subject: Re: deleting a file anywhere Reply with quote

@ 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
View user's profile Send private message AIM Address
socom1880



Joined: 14 Aug 2008
Posts: 34

PostPosted: Mon Aug 18, 2008 6:50 pm    Post subject: Reply with quote

yeah the setup name wouldnt be setup. it would be something like myprogramsetup.exe
Back to top
View user's profile Send private message
socom1880



Joined: 14 Aug 2008
Posts: 34

PostPosted: Mon Aug 18, 2008 7:04 pm    Post subject: Reply with quote

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
View user's profile Send private message
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Mon Aug 18, 2008 7:12 pm    Post subject: Reply with quote

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
View user's profile Send private message AIM Address
socom1880



Joined: 14 Aug 2008
Posts: 34

PostPosted: Mon Aug 18, 2008 7:20 pm    Post subject: Reply with quote

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
View user's profile Send private message
Razlin



Joined: 05 Nov 2007
Posts: 434
Location: canada

PostPosted: Tue Aug 19, 2008 12:50 pm    Post subject: Reply with quote

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
View user's profile Send private message
socom1880



Joined: 14 Aug 2008
Posts: 34

PostPosted: Tue Aug 19, 2008 5:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
Razlin



Joined: 05 Nov 2007
Posts: 434
Location: canada

PostPosted: Tue Aug 19, 2008 5:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
socom1880



Joined: 14 Aug 2008
Posts: 34

PostPosted: Tue Aug 19, 2008 5:44 pm    Post subject: Reply with quote

wait but then wouldnt that delete the autohotkey script, not the install file?
Back to top
View user's profile Send private message
Sivvy



Joined: 21 Jul 2008
Posts: 711
Location: Calgary, AB, Canada

PostPosted: Tue Aug 19, 2008 5:46 pm    Post subject: Reply with quote

It would delete the script currently running.
Back to top
View user's profile Send private message MSN Messenger
Krogdor



Joined: 18 Apr 2008
Posts: 1145
Location: The Interwebs

PostPosted: Tue Aug 19, 2008 6:04 pm    Post subject: Reply with quote

I believe he wants to delete an existing installer (not made in AHK), not make an installer that can delete itself.
Back to top
View user's profile Send private message AIM Address
socom1880



Joined: 14 Aug 2008
Posts: 34

PostPosted: Tue Aug 19, 2008 11:35 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group