need safe wild card for FileRemoveDir Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
AlleyArtwork
Posts: 43
Joined: 09 Jun 2015, 21:08

need safe wild card for FileRemoveDir

01 Aug 2018, 10:41

I'm looking for the correct way to do this, i'm trying to remove additional directories created by roaming profiles, example:
becca.smith
becca.smith.001
becca.smith.002

but I realized that i'll have issues with similar username such as "rebecca.smith", where becca.smith and rebecca.smith are 2 unique users.
In this example, What's the right way to do this without deleting rebecca.smith? or am i going about this entirely wrong?

Since this doesn't work: FileRemoveDir, \\path\users\becca.smith*, 1
My workaround to loop the directory, then match foldername with IfInString, would remove both users, becca.smith as well as rebecca.smith

Code: Select all

username = becca.smith

loop, \\path\users\*, 2, 0
{
	IfInString, a_loopfilename, %username%.			
		FileRemoveDir, %A_LoopFileFullPath%, 1
		
}
colt
Posts: 105
Joined: 04 Aug 2014, 23:12
Location: Portland Oregon

Re: need safe wild card for FileRemoveDir  Topic is solved

01 Aug 2018, 11:18

I am not sure what you file structure is like but could you check instead:

Code: Select all

IfInString, A_LoopFileFullPath, \%username%.
This would ensure you have their entire first name.

*fixed typo
User avatar
AlleyArtwork
Posts: 43
Joined: 09 Jun 2015, 21:08

Re: need safe wild card for FileRemoveDir

01 Aug 2018, 12:00

Hi Colt, It's so simple i feel embarrassed!
I'll test it and confirm shortly, but yes I think that will work. Thank you very much!

[edit]
Successfully tested with the following local test. This method doesn't delete the rebecca.smith folders.
I suppose i'll still need to be careful if there's a "becca.smithee" now.

[Edit 2]
I decided that when deleting the path for a user "becca.smith" i'm just going to have a line that removes that directory specifically, then after that will be the loop to look for matches to " \%username%. " to make sure the user.* folders are deleted without partial matches either (becca.smithee scenario).
Thanks guys!

Code: Select all

FileCreateDir, c:\temp\becca.smith
FileCreateDir, c:\temp\becca.smith.1
FileCreateDir, c:\temp\becca.smith.2
FileCreateDir, c:\temp\becca.smith.3
FileCreateDir, c:\temp\rebecca.smith
FileCreateDir, c:\temp\rebecca.smith.1
FileCreateDir, c:\temp\rebecca.smith.2
FileCreateDir, c:\temp\rebecca.smith.3

username = becca.smith

FileRemoveDir, c:\temp\%username%, 1

loop, C:\temp\*, 2, 0
{
	IfInString, A_LoopFileFullPath, \%username%.			
		FileRemoveDir, %A_LoopFileFullPath%, 1
}
Last edited by AlleyArtwork on 02 Aug 2018, 10:53, edited 4 times in total.
User avatar
jeeswg
Posts: 6648
Joined: 19 Dec 2016, 01:58
Location: UK

Re: need safe wild card for FileRemoveDir

01 Aug 2018, 12:21

- I would use this, to make sure that the file name starts with the string.

Code: Select all

if (InStr(A_LoopFileName, username) = 1)
- (For safety I might use MsgBox prior to each delete, or FileRecycle.)
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
AlleyArtwork
Posts: 43
Joined: 09 Jun 2015, 21:08

Re: need safe wild card for FileRemoveDir

01 Aug 2018, 12:54

Hi jeeswg,
Thank you for the alternative, this worked too!
It's always nice to see that you can do the same thing different ways.

I was trying to find this in the Help file but wasn't able to. Can you direct me to sources (or right thing to search for in Help) that show how this works and other ways to use this?
User avatar
jeeswg
Posts: 6648
Joined: 19 Dec 2016, 01:58
Location: UK

Re: need safe wild card for FileRemoveDir

01 Aug 2018, 13:14

These are the main pages I use. Cheers.
Alphabetical Command and Function Index | AutoHotkey
https://autohotkey.com/docs/commands/
Variables and Expressions
https://autohotkey.com/docs/Variables.htm
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA

Return to “Ask For Help”

Who is online

Users browsing this forum: Bill, Billykid, Bing [Bot], Bral, mtschwrz and 152 guests