MKDir not working

R

Robert_L_Ross

Here's my code:

UNITFOLDER = "G:\A F S\Monthly Reports\HiPath\CS\"
FILENAME = "MONTHLYC_"
NEWDIRECTORY = UNITFOLDER & RPTRUNDATE
If Dir(UNITFOLDER & RPTRUNDATE) = Null Then
MkDir (NEWDIRECTORY)
End If

Not sure why it's not working. It won't create the folder and I get an
error later. RPTRUNDATE is a variable (string) set earlier that in my
example I'm using "060206" as the string. I want it to first check if "G:\A
F S\Monthly Reports\HiPath\CS\060206" exists. If it doesn't, I want it to
create the folder. If it does exist, just keep going (earlier in the code I
delete any files in the directory).

Anyone have any idea why it's not working?

THX
 
R

RB Smissaert

You will have to check if UNITFOLDER exists as you can't make
a new folder in non-existent folder. In other words you can't make
4 or 5 folders in one go, only one at a time.

RBS
 
J

JMB

From one of Dave Peterson's old posts (which he reposted from Jim Rech). I
believe this API will create the folder and subfolders all in one go:


Declare Function MakePath Lib "imagehlp.dll" Alias _
"MakeSureDirectoryPathExists" (ByVal lpPath As String) As Long


Sub Test()
MakeDir "c:\aaa\bbb"
End Sub


Sub MakeDir(DirPath As String)
If Right(DirPath, 1) <> "\" Then DirPath = DirPath & "\"
MakePath DirPath
End Sub
 
R

RB Smissaert

Thanks for the tip.

RBS

JMB said:
From one of Dave Peterson's old posts (which he reposted from Jim Rech).
I
believe this API will create the folder and subfolders all in one go:


Declare Function MakePath Lib "imagehlp.dll" Alias _
"MakeSureDirectoryPathExists" (ByVal lpPath As String) As Long


Sub Test()
MakeDir "c:\aaa\bbb"
End Sub


Sub MakeDir(DirPath As String)
If Right(DirPath, 1) <> "\" Then DirPath = DirPath & "\"
MakePath DirPath
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top