-
May 14th, 2005, 10:58 AM
#1
Dir() with spaces??
Hello,
I am using the following code:
Code:
If fso.FileExists(Dir(DataPath & "\Data_*.txt")) then
'file exists...execute code
End If
This works great if my DataPath has no spaces in it. For example: C:\Test. But if my DataPath variable has spaces like C:\Documents and Settings...then it does not work.
How can I make this code work even if the variable DataPath has spaces? Thanks so much..
Steph!
-
May 14th, 2005, 11:21 AM
#2
Re: Dir() with spaces??
Try this - seems to work fine
Dim DataPath As String
DataPath = Text1.Text
If Dir(DataPath & "\*.txt") = "" Then
MsgBox "NO FILE"
Else
MsgBox "FILE EXISTS"
End If
-
May 14th, 2005, 11:51 AM
#3
Re: Dir() with spaces??
Thanks for your response. I am still having trouble though.
My scenario is I could have multiple data_*.txt files. These files get date stamped. For example, I could have data_05132005.txt and data_05142005.txt.
I need to check for the presence of a data_*.txt file and if it is there copy it to another directory and delete the original. My code below has always worked but I never had spaces in my paths. Now I have a case where the path does have spaces.
Code:
If fso.FileExists(Dir(DataPath & "\Data_File_*.txt")) Then
fso.CopyFile Dir(DataPath & "\Data_File_*.txt), "C:\Data"
fso.DeleteFile Dir(DataPath & "\Data_File_*.txt)
End If
Again, this has worked for me as long as DataPath had no spaces. There has to be some way I can handle DataPath correctly when it has spaces? I've searched around and I can not find anything that is relevant.
Thanks again!
Steph
-
May 14th, 2005, 12:27 PM
#4
Re: Dir() with spaces??
The following works
Private Sub Command1_Click()
DataPath = "C:\My Data Directory"
If Dir(DataPath & "\Data_File_*.txt") <> "" Then
FileIn = Dir(DataPath & "\Data_File_*.txt")
PathIn = DataPath & "\" & Dir(DataPath & "\Data_File_*.txt")
FileCopy PathIn, ("C:\Data\" & FileIn)
Kill PathIn
End If
End Sub
Your problem was not the spaces in the Directory Name - it was
fso.CopyFile Dir(DataPath & "\Data_File_*.txt), "C:\Data"
should have been
fso.CopyFile Dir(DataPath & "\Data_File_*.txt), "C:\Data\" & filename
You need a destination filename in a copy function - not just a destination directory name
-
May 14th, 2005, 12:49 PM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|