Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Copy file 1

Status
Not open for further replies.

rmelnyck

Technical User
Sep 26, 2003
27
US
I am trying to check if a folder exists, if it doesn't I want to create it. This works no problem. The seocnd part is that I want to move a file from one folder to another but I keep getting a Run Time Error '5' Invalid procedure call or argument. It must be something stupid I am not seeing. Here is the code. Thanks!

Sub Create_Folder_If_NonExistant()

Dim fso
Dim c
Dim fol As String
fol = "C:\SystemServices"
sfol = "K:\GlobalDistribution\Combined Reports\ProgressReporter.dll"
dfol = "C:\SystemServices"

Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(fol) Then
fso.CreateFolder (fol)
fso.CopyFile sfo1, dfo1
Else
MsgBox fol & " already exists!"
fso.CopyFile sfo1, dfo1
End If

End Sub

 
From VB Help on FSO

If source contains wildcard characters or destination ends with a path separator (\), it is assumed that destination is an existing folder in which to copy matching files. Otherwise, destination is assumed to be the name of a file to create.

Your destination does not end with a "\" so FSO is assuming that it's a file name ... not a directory.
 
Maybe type 'o


>sfol = "K:\GlobalDistribution\Combined Reports\ProgressReporter.dll"
>dfol = "C:\SystemServices"

>fso.CopyFile sfo1, dfo1

look like a 1(one) vs l (L)

I was standing in the park, wondering why frisbees got bigger as they came closer... then it hit me!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top