 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Freekster Guest
|
Posted: Tue Mar 08, 2005 5:38 pm Post subject: Please help |
|
|
I am nnew and in need of help
I want use "Loop, %MyEdit%, 1, 1"
To find files on my drive , say for example D:\
Again I want to show a Msg pointing to the location of a file and asking if I wanted to delete it, If I say no to msg
"IfMsgBox, No"
It continues to show me locations one after another and if I say yes, it deletes the file and show me another files location as per my criteria for search I put in "%MyEdit%'
Can someone help ? |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Tue Mar 08, 2005 7:43 pm Post subject: |
|
|
Yes, I could.
What code do you already have?
And what do you want to know? _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Freekster Guest
|
Posted: Tue Mar 08, 2005 8:02 pm Post subject: Code |
|
|
So far I have this
| Code: | InputBox, FileName, Type the name of the file or folder to delete, , , , 100
If FileName =
{
MsgBox 4, OoopS!, No name was entered. Try again ?
IfMsgBox, No, ExitApp
Reload
}
Loop, %FileName%, 1, 1
MsgBox, 4, , Do you want to delete %A_LoopFileLongPath%
IfMsgBox, No, Continue
FileDelete, %A_LoopField% |
But if I say yes, It deletes all files found in the loop.
How can I make it to select a file to delete and if I want I could leave A few files alone and delete some found by the code |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Tue Mar 08, 2005 8:44 pm Post subject: |
|
|
Hi Freekster.
Please use the "Code" button when insert code. It is easier to read then.
To you code: There are {} missing for the last loop.
Instead of | Code: | IfMsgBox, No, Continue
FileDelete, %A_LoopField%
|
why not (mark that I have changed the var) | Code: | IfMsgBox, Yes
{
FileDelete, %A_LoopFileFullPath%
}
|
_________________ Ciao
toralf 
Last edited by toralf on Tue Mar 08, 2005 8:46 pm; edited 1 time in total |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5376 Location: /b/
|
Posted: Tue Mar 08, 2005 8:45 pm Post subject: Re: Code |
|
|
| Freekster wrote: | InputBox, FileName, Type the name of the file or folder to delete, , , , 100
If FileName =
{
MsgBox 4, OoopS!, No name was entered. Try again ?
IfMsgBox, No, ExitApp
Reload
}
Loop, %FileName%, 1, 1
MsgBox, 4, , Do you want to delete %A_LoopFileLongPath%
IfMsgBox, No, Continue
FileDelete, %A_LoopField% |
Change the 'Continue' to Return.
It might not make a difference replace the last line of your code with:
IfMsgBox, Yes
FileDelete, %A_LoopField% _________________
 |
|
| Back to top |
|
 |
Freekster Guest
|
Posted: Tue Mar 08, 2005 9:22 pm Post subject: |
|
|
Thanks guys
But I found a major flaw in my code.
| Code: | | Loop, %MyFile%, 1 ,1 |
It is destined to retrieve both files and folder
if it finds a folder, it can not delete it with command
| Code: | | FileDelete, %A_LoopFileLongPath% |
It has to be
| Code: | | FileRemoveDir, %A_LoopFileLongPath% |
I corrected it and am going to try it now
If it works, I will let you know |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Tue Mar 08, 2005 9:41 pm Post subject: |
|
|
| Good eye. I looked at it for a while and I didn't spot that. |
|
| Back to top |
|
 |
toralf
Joined: 31 Jan 2005 Posts: 3841 Location: Bremen, Germany
|
Posted: Tue Mar 08, 2005 10:14 pm Post subject: |
|
|
It was never pointed out to delte folders as well.
Never mind, come back when you have problems. _________________ Ciao
toralf  |
|
| Back to top |
|
 |
Freekster Guest
|
Posted: Tue Mar 08, 2005 11:29 pm Post subject: Eureka |
|
|
OK Guys, I am done now
This final code Checks a given file or folder name on Drives C:\ to L:\
(I have Drives C:\ D: ...... J:\) someone may have a drive L:\, who knows
Anyways, It also cheks if you have these many drives, checks if any of these drives are CDROMS etc.
After that it starts with drive C:\ and if more than 99 files or folder found, asks you if you want to go on one by one to delete them. ( it usually happens when you use Wild Cards for example *.html etc )
and it goes checking untill your last hard drive.
Here is the code.
PS: I am new with AHK so it may not match your criteria of a good code but I am here to learn from Guys like Toraff, or Titan or Rajat. Please be gentle
| Code: |
FileDelete, %Temp%\Temp.txt
InputBox, FileName, Type the name of the file or folder to delete, , , , 100
If FileName =
{
MsgBox 4, OoopS!, No name was entered. Try again ?
IfMsgBox, No, ExitApp
Reload
}
;**************************************************************************************
; SEARCH DRIVE C
;**************************************************************************************
DC:
SetWorkingDir, C:\
FileDelete, %Temp%\Temp.txt
Loop, %FileName%, 1, 1
FileAppend, %A_LoopFileLongPath%`n, %Temp%\Temp.txt
FileReadLine, MyLineC, %Temp%\Temp.txt, 100
If MyLineC =
GoTo, StartC
{
MsgBox 4, OoopS!, There are more then 99 files and folders matched your criterion on Drive [ C`:`\ ]`n`n`n`nDo you want to continue ?
IfMsgBox, No, GoTo, DD
}
StartC:
Loop, %FileName%, 2, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileRemoveDir, %A_LoopFileLongPath%
}
Loop, %FileName%, 0, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileDelete, %A_LoopFileLongPath%
}
;**************************************************************************************
; SEARCH DRIVE D
;**************************************************************************************
DD:
SetWorkingDir, D:\
FileDelete, %Temp%\Temp.txt
Loop, %FileName%, 1, 1
FileAppend, %A_LoopFileLongPath%`n, %Temp%\Temp.txt
FileReadLine, MyLineD, %Temp%\Temp.txt, 100
If MyLineD =
GoTo, StartD
{
MsgBox 4, OoopS!, There are more then 99 files and folders matched your criterion on Drive [ D`:`\ ]`n`n`n`nDo you want to continue ?
IfMsgBox, No, GoTo, DE
}
StartD:
Loop, %FileName%, 2, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileRemoveDir, %A_LoopFileLongPath%
}
Loop, %FileName%, 0, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileDelete, %A_LoopFileLongPath%
}
;**************************************************************************************
; SEARCH DRIVE E
;**************************************************************************************
DE:
DriveGet, DStateE, List, CDROM
IfInString, DStateE, E, GoTo, End
DriveGet, DSatusE, List
IfNotInString, DSatusE, E, GoTo, End
SetWorkingDir, E:\
FileDelete, %Temp%\Temp.txt
Loop, %FileName%, 1, 1
FileAppend, %A_LoopFileLongPath%`n, %Temp%\Temp.txt
FileReadLine, MyLineE, %Temp%\Temp.txt, 100
If MyLineE =
GoTo, StartE
{
MsgBox 4, OoopS!, There are more then 99 files and folders matched your criterion on Drive [ E`:`\ ]`n`n`n`nDo you want to continue ?
IfMsgBox, No, GoTo, DF
}
StartE:
Loop, %FileName%, 2, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileRemoveDir, %A_LoopFileLongPath%
}
Loop, %FileName%, 0, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileDelete, %A_LoopFileLongPath%
}
;**************************************************************************************
; SFARCH DRIVF F
;**************************************************************************************
DF:
DriveGet, DStateF, List, CDROM
IfInString, DStateF, F, GoTo, End
DriveGet, DSatusF, List
IfNotInString, DSatusF, F, GoTo, End
SetWorkingDir, F:\
FileDelete, %Temp%\Temp.txt
Loop, %FileName%, 1, 1
FileAppend, %A_LoopFileLongPath%`n, %Temp%\Temp.txt
FileReadLine, MyLineF, %Temp%\Temp.txt, 100
If MyLineF =
GoTo, StartF
{
MsgBox 4, OoopS!, There are more then 99 files and folders matched your criterion on Drive [ F`:`\ ]`n`n`n`nDo you want to continue ?
IfMsgBox, No, GoTo, DG
}
StartF:
Loop, %FileName%, 2, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileRemoveDir, %A_LoopFileLongPath%
}
Loop, %FileName%, 0, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileDelete, %A_LoopFileLongPath%
}
;**************************************************************************************
; SGARCH DRIVG G
;**************************************************************************************
DG:
DriveGet, DStateG, List, CDROM
IfInString, DStateG, G, GoTo, End
DriveGet, DSatusG, List
IfNotInString, DSatusG, G, GoTo, End
SetWorkingDir, G:\
FileDelete, %Temp%\Temp.txt
Loop, %FileName%, 1, 1
FileAppend, %A_LoopFileLongPath%`n, %Temp%\Temp.txt
FileReadLine, MyLineG, %Temp%\Temp.txt, 100
If MyLineG =
GoTo, StartG
{
MsgBox 4, OoopS!, There are more then 99 files and folders matched your criterion on Drive [ G`:`\ ]`n`n`n`nDo you want to continue ?
IfMsgBox, No, GoTo, DH
}
StartG:
Loop, %FileName%, 2, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileRemoveDir, %A_LoopFileLongPath%
}
Loop, %FileName%, 0, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileDelete, %A_LoopFileLongPath%
}
;**************************************************************************************
; SHARCH DRIVH H
;**************************************************************************************
DH:
DriveGet, DStateH, List, CDROM
IfInString, DStateH, H, GoTo, End
DriveGet, DSatusH, List
IfNotInString, DSatusH, H, GoTo, End
SetWorkingDir, H:\
FileDelete, %Temp%\Temp.txt
Loop, %FileName%, 1, 1
FileAppend, %A_LoopFileLongPath%`n, %Temp%\Temp.txt
FileReadLine, MyLineH, %Temp%\Temp.txt, 100
If MyLineH =
GoTo, StartH
{
MsgBox 4, OoopS!, There are more then 99 files and folders matched your criterion on Drive [ H`:`\ ]`n`n`n`nDo you want to continue ?
IfMsgBox, No, GoTo, DI
}
StartH:
Loop, %FileName%, 2, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileRemoveDir, %A_LoopFileLongPath%
}
Loop, %FileName%, 0, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileDelete, %A_LoopFileLongPath%
}
;**************************************************************************************
; SHARCH DRIVH I
;**************************************************************************************
DI:
DriveGet, DStateI, List, CDROM
IfInString, DStateI, I, GoTo, End
DriveGet, DSatusI, List
IfNotInString, DSatusI, I, GoTo, End
SetWorkingDir, I:\
FileDelete, %Temp%\Temp.txt
Loop, %FileName%, 1, 1
FileAppend, %A_LoopFileLongPath%`n, %Temp%\Temp.txt
FileReadLine, MyLineI, %Temp%\Temp.txt, 100
If MyLineI =
GoTo, StartI
{
MsgBox 4, OoopS!, There are more then 99 files and folders matched your criterion on Drive [ I`:`\ ]`n`n`n`nDo you want to continue ?
IfMsgBox, No, GoTo, DJ
}
StartI:
Loop, %FileName%, 2, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileRemoveDir, %A_LoopFileLongPath%
}
Loop, %FileName%, 0, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileDelete, %A_LoopFileLongPath%
}
;**************************************************************************************
; SHARCH DRIVH J
;**************************************************************************************
DJ:
DriveGet, DStateJ, List, CDROM
IfInString, DStateJ, J, GoTo, End
DriveGet, DSatusJ, List
IfNotInString, DSatusJ, J, GoTo, End
SetWorkingDir, J:\
FileDelete, %Temp%\Temp.txt
Loop, %FileName%, 1, 1
FileAppend, %A_LoopFileLongPath%`n, %Temp%\Temp.txt
FileReadLine, MyLineJ, %Temp%\Temp.txt, 100
If MyLineJ =
GoTo, StartJ
{
MsgBox 4, OoopS!, There are more then 99 files and folders matched your criterion on Drive [ J`:`\ ]`n`n`n`nDo you want to continue ?
IfMsgBox, No, GoTo, DK
}
StartJ:
Loop, %FileName%, 2, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileRemoveDir, %A_LoopFileLongPath%
}
Loop, %FileName%, 0, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileDelete, %A_LoopFileLongPath%
}
;**************************************************************************************
; SHARCH DRIVH K
;**************************************************************************************
DK:
DriveGet, DStateK, List, CDROM
IfInString, DStateK, K, GoTo, End
DriveGet, DSatusK, List
IfNotInString, DSatusK, K, GoTo, End
SetWorkingDir, K:\
FileDelete, %Temp%\Temp.txt
Loop, %FileName%, 1, 1
FileAppend, %A_LoopFileLongPath%, %Temp%\Temp.txt
FileReadLine, MyLineK, %Temp%\Temp.txt, 100
If MyLineK =
GoTo, StartK
{
MsgBox 4, OoopS!, There are more then 99 files and folders matched your criterion on Drive [ K`:`\ ]`n`n`n`nDo you want to continue ?
IfMsgBox, No, GoTo, DL
}
StartK:
Loop, %FileName%, 2, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileRemoveDir, %A_LoopFileLongPath%
}
Loop, %FileName%, 0, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileDelete, %A_LoopFileLongPath%
}
;**************************************************************************************
; SHARCH DRIVH L
;**************************************************************************************
DL:
DriveGet, DStateL, List, CDROM
IfInString, DStateL, L, GoTo, End
DriveGet, DSatusL, List
IfNotInString, DSatusL, L, GoTo, End
SetWorkingDir, L:\
FileDelete, %Temp%\Temp.txt
Loop, %FileName%, 1, 1
FileAppend, %A_LoopFileLongPath%, %Temp%\Temp.txt
FileReadLine, MyLineL, %Temp%\Temp.txt, 100
If MyLineL =
GoTo, StartL
{
MsgBox 4, OoopS!, There are more then 99 files and folders matched your criterion on Drive [ L`:`\ ]`n`n`n`nDo you want to continue ?
IfMsgBox, No, GoTo, End
}
StartL:
Loop, %FileName%, 2, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileRemoveDir, %A_LoopFileLongPath%
}
Loop, %FileName%, 0, 1
{
MsgBox 4, Caution!, This file or folder found`, matching criterion [ %FileName% ]`n`n[ %A_LoopFileLongPath% ]`n`n`n`nDelete it ?
IfMsgBox, No, Continue
FileDelete, %A_LoopFileLongPath%
}
End:
FileDelete, %Temp%\Temp.txt
ExitApp |
Let me know what you think of this blather of mine |
|
| Back to top |
|
 |
Titan
Joined: 11 Aug 2004 Posts: 5376 Location: /b/
|
Posted: Wed Mar 09, 2005 12:26 am Post subject: |
|
|
One day, scripting with autohotkey, my script accidentally deleted a chunk of My Documents where all my files were; luckily I managed to retrive some back but I tend to steer away from the FileDelete command now after this silly incident.
Analysing your code it seemed like a good useful script (maybe it'll come hand in future?) - thanks for sharing. _________________
 |
|
| Back to top |
|
 |
Freekster Guest
|
Posted: Wed Mar 09, 2005 12:53 am Post subject: Thanxs |
|
|
Thanks Titan, coming from you it means a lot.
Anyway, since I have you here. Where can I get AHK Studio ? |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Wed Mar 09, 2005 12:55 am Post subject: |
|
|
Someone has a fanboy...  |
|
| Back to top |
|
 |
Freekster Guest
|
Posted: Wed Mar 09, 2005 1:04 am Post subject: |
|
|
Hey! jonny
I think I missed you out in my compliments to Titan, Rajat and such. My Mistake.
Actually I am a big fan of good, useful scripts. I am new with AHK but one day I will script for a New OS with it [ any names for it ? ) and get rid of my Useless, Good for nothing WINDOWS |
|
| Back to top |
|
 |
jonny
Joined: 13 Nov 2004 Posts: 3004 Location: Minnesota
|
Posted: Wed Mar 09, 2005 1:08 am Post subject: |
|
|
Well, I don't have much in the way of scriptage... I've made some, but my masterpiece has yet to come out. deguix has mouse gestures, keyboardfreak has iswitchw, Rajat has Smartgui (among countless others), the list goes on. All great scripts. I'd say the best one I've made was EWD (the newer one), and that wasn't very large at all. If you search the forums, I've got a few deprecated scripts back there, but I never really finished any...
P.S. I've yet to test AutoHotkey on Linux, but I don't expect the results to be promising when I do. Maybe you can help me port it!  |
|
| Back to top |
|
 |
Freekster Guest
|
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|