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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Spaces in file path causing issues 2

Status
Not open for further replies.

royalcheese

Technical User
Dec 5, 2005
111
GB

Hi All

I have a function that ftps a file from a to b , the issue im getting is when the file path is larger / has spaces I think as an example

"C:\Program Files\File Program\Upload" - Errors because of spaces I think

"C:\Upload" Works fine.

My Question is how can get the Longer string with spaces etc to work.

Many Thanks


Chris
 
Perhaps you could use the following function to get the short name to the file:
Code:
Public Function ShowShortName(filespec) As String
    Dim fs As FileSystemObject
    Dim f As File
    Dim s As String
    
    Set fs = New FileSystemObject
    Set f = fs.GetFile(filespec)
    
    ShowShortName = f.ShortPath & "\" & f.ShortName
    
End Function
You need to make a reference to the Microsoft Scripting Runtime library to use the FileSystemObject.
 
If you have the filepath stored in a variable, try modifying it like below.

strFilePath = """C:\Program Files\File Program\Upload"""

This encloses the filepath in double quotes (Try debug.print) which should resolve your problem.

------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
Joe At work

This looks good but i get issues

I am calling like this

newupload = ShowShortName(uPfUpload & "\" & nsfil)

uPFupload : contains the folder name
nsFil : contains the file name

I have ensured that the scripting dll is installed.

the errors comes on

Code:
Set f = fs.GetFile(filespec) ' concatinated file string

the error is "File Not Found" with a runtime error of '53'

How can I get round this ?

Thanks very much in advance and thanks for help already

Cheers

Chris


 
If uPfUpload contains a "\" at the end, the file path will come out incorrect.

Try removing the "\" from newupload = ShowShortName(uPfUpload & "\" & nsfil)

After removing it, the code will read

newupload = ShowShortName(uPfUpload & nsfil)



------------------------------------------
The faulty interface lies between the chair and the keyboard.
 
No change if i take it out , the file path is stored with out the "\", so this is needed to make the file path continue and seperate the file from the path.



 
Are you sure the filespec exists?

If fs.FileExists(filespec) Then
 
ahh yes on letter out of place this works fine now , cheers guys !

Mucho Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top