Folder Deletion

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
etdeshon
Posts: 9
Joined: 19 Apr 2017, 18:35

Folder Deletion

21 Jul 2017, 14:50

Hello everyone,

The idea of the script (below) is to read a .txt file, display the folder properties of the copied folder within "testfolders1" and "testfolders2" to confirm size of transfer (different script that I've already created that works), then delete the respective folder from "testfolders1" upon clicking "Yes" through a Gui button and continuing to the next step, or force stopping if no is selected.

I am running into an issue where the script just freezes upon clicking "Yes" and will not progress. I thought this was just due to the folder deleting taking time, but I've left it running for 30 minutes on a folder that is only 1 MB.

Something additional that I am attempting to do, is upon completion of the deletion of the folder, I want the line deleted from the textfile (you'll see where I attempt to call it out in the code). I would also like to allow multiple instances of a transfer to run if the file has more than 5 folders to delete. With the code I have below, it will only allow one folder to be deleted at a time, and I would like to set it to have up to 5-10 transferring at a time, if possible. I'm just unsure of how to code the simultaneous deletions.

Here is the code I've written:

Code: Select all

#singleinstance force

Loop, read, C:\Users\deshone\Desktop\AHK\File.txt
{
	Loop, parse, A_LoopReadLine, `n
	{
		Gui, Font, s14
		Gui, Add, Text,, Confirm Deletion for %A_LoopField%?
		Gui, Font, s10
		Gui, Add, Button, x70 y40, Yes
		Gui, Add, Button, x180 y40, No
		Gui, Show
		
		Run, properties "C:\Users\deshone\Desktop\AHK\testfolders1\%A_LoopField%"
		Run, properties "C:\Users\deshone\Desktop\AHK\testfolders2\%A_LoopField%"

		sleep 60000

		ButtonNo:
		Gui, Hide
		MsgBox, No has been clicked or session timed out - STOPPING SCRIPT.`nPlease reload script when ready.
		exitapp
		return
		
		ButtonYes:
		Gui, Hide
		Progress,%a_index%,%a_LoopField%
		FileRemoveDir, C:\Users\deshone\Desktop\AHK\testfolders1\%A_LoopField%, 1
		%a_LoopField% = ""
		return
				
		GuiClose:
		ExitApp
	}
}
Please let me know if there is any more information or questions I can answer regarding this.

Thanks!
etdeshon
etdeshon
Posts: 9
Joined: 19 Apr 2017, 18:35

Re: Folder Deletion

24 Jul 2017, 12:39

Bump. I'm curious on if anyone has any advice on this. Hopefully someone can look into this.
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Folder Deletion

24 Jul 2017, 13:01

Hi.
My english is not the best, so I have read your question long time before, but have not really understand, what you want to do. Even I don't know the content of your File.txt.
Apart from this, as I know, Labels in Loops are not possible, even your first loop parses for word wrap (`n) and stores this in A_LoopReadLine. An additional parsing for wrap, as your script does, will not able to find any word wrap, because your first loop has parsed theese.
All in all, try first to create a bit more functional script and tell, what is inside your File.txt.
You can put some MsgBox inside your script to test, if the code is processed. Put your labels outside your loops and respond them with Gosub.
Sorry, but my speaking language differences are making more support not possible at this time. If I had more specific information maybe I would take a bit more time to help.
Einfach nur ein toller Typ. :mrgreen:
etdeshon
Posts: 9
Joined: 19 Apr 2017, 18:35

Re: Folder Deletion

24 Jul 2017, 13:10

That actually helps! Thank you!

My .txt file includes the names of folders that are meant to be deleted within the specified drive listed in the code. Hope this helps!
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Folder Deletion

24 Jul 2017, 14:00

Hi.
As I don't really know, what do you mean with getting properties, I give you a simplified example for parsing your File.txt.
In my example the content of File.txt is

Code: Select all

C:\Users\awe\Desktop\Neuer Ordner\Neuer Ordner
C:\Users\awe\Desktop\Neuer Ordner\Neuer Ordner (2)
C:\Users\awe\Desktop\Neuer Ordner\Neuer Ordner (3)
The code for parsing the File.txt is

Code: Select all

Gui, Font, s14
Gui, Add, Button, x280 y40 gStart, Start
Gui, Show, , Confirm Deletion?
return

ButtonNo:
exitapp
return

ButtonYes:
FileRemoveDir, %LineText%, 1
return
		
GuiClose:
ExitApp

Start:
Loop, read, C:\Users\deshone\Desktop\AHK\File.txt, `n, `r
{
	LineText := A_LoopReadLine
	Msgbox, 4,, %A_LoopReadLine%`n`nWant to delete?
	IfMsgBox Yes
	Gosub ButtonYes
}
MsgBox Ready
return
As you can see, all labels are outside the loop. For special information about the Folders look into the reference of Loop (files & folders).
Einfach nur ein toller Typ. :mrgreen:
etdeshon
Posts: 9
Joined: 19 Apr 2017, 18:35

Re: Folder Deletion

24 Jul 2017, 14:00

I was able to resolve the core issue of my code with a variable callout within the loop and running a GoSub as the button commands:

Code: Select all

#singleinstance force

Loop, read, C:\Users\deshone\Desktop\AHK\File.txt
{
	Loop, parse, A_LoopReadLine, `n
	{
		Gui, Font, s14
		Gui, Add, Text,, Confirm Deletion for %A_LoopField%?
		Gui, Font, s10
		Gui, Add, Button, x70 y40, Yes
		Gui, Add, Button, x180 y40, No
		Gui, Show
		
		Run, properties "C:\Users\deshone\Desktop\AHK\testfolders1\%A_LoopField%"
		Run, properties "C:\Users\deshone\Desktop\AHK\testfolders2\%A_LoopField%"

		file = %A_LoopField%

		sleep 60000

		ButtonNo:
		GoSub, Stop
		
		ButtonYes:
		GoSub, Delete
		return
				
		GuiClose:
		ExitApp
	}
}

Delete:
Gui, Hide
Progress,%a_index%,%file%
FileRemoveDir, C:\Users\deshone\Desktop\AHK\testfolders1\%file%, 1
return

Stop:
Gui, Hide
MsgBox, No has been clicked or session timed out - STOPPING SCRIPT.`nPlease reload script when ready.
exitapp
User avatar
divanebaba
Posts: 805
Joined: 20 Dec 2016, 03:53
Location: Diaspora

Re: Folder Deletion

27 Jul 2017, 14:19

Hi.
I'm sorry to tell, that your second example can not work.
Look here:

Code: Select all

Loop, read, C:\Users\deshone\Desktop\AHK\File.txt
{
	Loop, parse, A_LoopReadLine, `n
		{
		...
The first loop looks for the first wordwrap (`n)
If it finds one wordwrap, it stores the text left of the wordwrap into A_LoopReadLine. A_LoopReadLine now contains only the text without any wordwrap. Parsing in the second loop with (`n) as delimeter will get no results.

Even these

Code: Select all

...
ButtonNo:
GoSub, Stop
		
ButtonYes:
GoSub, Delete
return
				
GuiClose:
ExitApp
...
are called labels and they has to be outside your loop.
Your code can not work without correcting these.
Einfach nur ein toller Typ. :mrgreen:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Exies, hiahkforum, JoeWinograd, mikeyww and 144 guests