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

Re: checking if folder exists and if not create it by Perry

Perry
Sun May 20 10:22:27 CDT 2007

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



"red6000" <red1000002001@yahoo.com> schreef in bericht
news:465065b2$0$3832$c3e8da3@news.astraweb.com...
> 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
>
>