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

Scripting.FileSystemObject- GetFile

Status
Not open for further replies.

drkestrel

MIS
Sep 25, 2000
439
0
0
GB
I got a problem as demonstrated by thee following code. The test for
Code:
FileExists
returns
Code:
True
, and also
Code:
MsgBox strLatestPackageFile
also looks legitimate. However, I get "File Not Found" error when
Code:
GetFile
is called on the same file
Code:
strLatestPackagefile
has been initialised to "d:\deployment\20040126-103023.sdo".

Whatt could be the error. I can't think of anything wrong!!

Code:
Dim  objTmp         
Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")
MsgBox strLatestPackageFile
MsgBox "c1" & Vbcrlf & Err.Description
MsgBox objTmp = objFileSystemObject.FileExists(strLatestPackageFile)
MsgBox "c2" & Vbcrlf & Err.Description
Set objTmp = objFileSystemObject.GetFile(strLatestPackageFile)
MsgBox "c3" & Vbcrlf & Err.Description
 
Try:
Code:
Dim objTmp         
Dim bExists
Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")
MsgBox strLatestPackageFile
MsgBox "c1" & Vbcrlf & Err.Description
bExists = objFileSystemObject.FileExists(strLatestPackageFile)
MsgBox bExists
MsgBox "c2" & Vbcrlf & Err.Description
Set objTmp = objFileSystemObject.GetFile(strLatestPackageFile)
MsgBox "c3" & Vbcrlf & Err.Description
and see what you get...

[tt]________________________________________________________________
[pc2]Roger
Life is a game of cards in which the deck contains only jokers.[/tt]
 
Oh, FileExists return false, but the the file indicated by MsgBox strLatestPackageFile does exists.

why is this!? Do i need to escape the slash (\) or what?
 
This is in a WSF file. If I take out the code and put in a VBS file. Same error!

Regardless of whether I use cscript or wscript to run the script on WinXP Pro SP2.
 
Who/what is creating the file represented in strLatestPackageFile? And how long after creation are you running your code?
 
No reason to escape "\" in VBScript.

The code runs OK for me (Win98 SE & Win2000). Can't try it on XP.



[tt]________________________________________________________________
[pc2]Roger
Life is a game of cards in which the deck contains only jokers.[/tt]
 
It turns out that the problem is caused by an extra VbCrLf at the end of strLatestPackageFile. That's why it appears visually OK in the MsgBox but FileExists returns false.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top