if not dirExists

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
sbrady19
Posts: 338
Joined: 12 Apr 2018, 05:22
Location: Central Florida
Contact:

if not dirExists

13 Apr 2024, 09:04

Code: Select all

Loop Files ProdFolder '\' UserInput ' *', 'D' 
{

try
{
MsgBox A_LoopFileFullPath      ;THIS WORKS IF FOLDER EXISTS
}

if not DirExist(A_LoopFileName)

;IF NO FOLDER WITH USERINPUT NAME, NOTHING
;If folder does exists, it makes a folder anyway  mind boggling
DirCreate ProdFolder '\' UserInput     
}
User avatar
mikeyww
Posts: 27012
Joined: 09 Sep 2014, 18:38

Re: if not dirExists

13 Apr 2024, 09:12

The loop executes only for matches, so your If condition would never be met or, at best, you are checking something in an unintended way (e.g., possibly looking for a file or directory name in the current working directory). You cannot loop through something that does not exist.

My recollection is that the full path is the entire string returned, but the file name is only the final or terminal path element. Test it. Find out what is returned. Since you are looping through directories, use the full path to identify the directory path.

If your goal is to create a single directory with a known path, then this would not be done within the loop. You do not need any loop to create a single directory.
sbrady19
Posts: 338
Joined: 12 Apr 2018, 05:22
Location: Central Florida
Contact:

Re: if not dirExists

13 Apr 2024, 11:26

Let me explain my need.

If project folder xyz123 does not exist in a master folder. Make one.
User avatar
boiler
Posts: 16997
Joined: 21 Dec 2014, 02:44

Re: if not dirExists

13 Apr 2024, 14:42

sbrady19 wrote: Let me explain my need.
He understood your need. You are not understanding the answer: “this would not be done within the loop.” Here it is in code (where UserInput and ProdFolder are previously assigned):

Code: Select all

if not DirExist(ProdFolder '\' UserInput)
	DirCreate ProdFolder '\' UserInput
That’s it. No looping or anything. As mikeyww explained, when you put those lines inside the loop that you defined, they would never execute when that folder doesn’t exist because the loop would execute zero times.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: Lufitsu, songdg, yakunins and 62 guests