checking if folder exists and if not create it

R

red6000

Hi, I've got some code that move files, but I need the code to check if the
destination folder exists and if it doesn;t to create it.

I think I can do the code to create if, but not sure how to check if it
exists?

My code is below. I need help with the ***** bit. Thanks for any help.

Dim oldfilepath as String
Dim newfilepath as String
Dim myFile as String
Dim fso

oldfilePath = "C:\old\"
newfilePath = "C:\new\"
myFile = "randomfile.doc"
Set fso = CreateObject("Scripting.FileSystemObject")

***** if newfilepath exists then
'do nothing
else
fso.CreateFolder(newfilepath)
end if
oldfilepath = oldfilepath & myFile
newfilepath = oldfilepath & myFile

Name oldfilepath As newfilepath
 
P

Perry

Use FolderExists() function of filesystemobject

(also check out: FileExists() function)

Like in
If fso.Folderexists("c:\Anyfolder") then

....etc


--
Krgrds,
Perry

System:
Vista/Office Ultimate
VS2005/VSTO2005 SE
 

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