Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - HELP! fileExist function always return 'FALSE'

Reply
 
Old 06-09-2009   #1 (permalink)
youu917


 
 

HELP! fileExist function always return 'FALSE'

HI all,

I have a problem when trying to pass a string into the fileExist
function.
the code will get the filename from sql database, and pass into the
fileExist function.
then i use: filename=rs('field')
if fs.fileExist(filename) then
fs.Deletefile(filename)
end

I've tried to write out the filename, it show me a correct path and
filename to the path, whille i changed the filename to string "C:\path
\file" it works fine. however when i use a variable: filename, the
fileExist always return "false"

anyone can tell me how to solve the problem?
thank you.

My System SpecsSystem Spec
Old 06-09-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: HELP! fileExist function always return 'FALSE'


<youu917@xxxxxx> wrote in message
news:afee6132-be4f-45c2-ae0d-94447793ef52@xxxxxx
Quote:

> HI all,
>
> I have a problem when trying to pass a string into the fileExist
> function.
> the code will get the filename from sql database, and pass into the
> fileExist function.
> then i use: filename=rs('field')
> if fs.fileExist(filename) then
> fs.Deletefile(filename)
> end
>
> I've tried to write out the filename, it show me a correct path and
> filename to the path, whille i changed the filename to string "C:\path
> \file" it works fine. however when i use a variable: filename, the
> fileExist always return "false"
>
> anyone can tell me how to solve the problem?
> thank you.
Your code fragment looks like pseudo-code, not like the real thing. Is it
supposed to be VB Script? Let's have the actual fragment from your program!


My System SpecsSystem Spec
Old 06-09-2009   #3 (permalink)
ekkehard.horner


 
 

Re: HELP! fileExist function always return 'FALSE'

youu917@xxxxxx schrieb:
Quote:

> HI all,
>
> I have a problem when trying to pass a string into the fileExist
> function.
> the code will get the filename from sql database, and pass into the
> fileExist function.
change this:
Quote:

> then i use: filename=rs('field')
> if fs.fileExist(filename) then
> fs.Deletefile(filename)
> end
to:
filename = rs( "field" )
MsgBox ">" & filename & "<"
If fs.FileExists( filename ) Then
fs.DeleteFile filename
End If

to check for whitespace. If there are leading or trailing blanks, use

filename = Trim( rs( "field" ) )

for other whitespace use (or ask for) a RegExp.
Quote:

> I've tried to write out the filename, it show me a correct path and
> filename to the path, whille i changed the filename to string "C:\path
> \file" it works fine. however when i use a variable: filename, the
> fileExist always return "false"
>
> anyone can tell me how to solve the problem?
> thank you.
My System SpecsSystem Spec
Old 06-09-2009   #4 (permalink)
Todd Vargo


 
 

Re: HELP! fileExist function always return 'FALSE'

"ekkehard.horner" <ekkehard.horner@xxxxxx> wrote in message
news:4a2e42fc$0$32676$9b4e6d93@xxxxxx-online.net...
Quote:

> youu917@xxxxxx schrieb:
Quote:

> > HI all,
> >
> > I have a problem when trying to pass a string into the fileExist
> > function.
> > the code will get the filename from sql database, and pass into the
> > fileExist function.
>
> change this:
Quote:

> > then i use: filename=rs('field')
> > if fs.fileExist(filename) then
> > fs.Deletefile(filename)
> > end
>
> to:
> filename = rs( "field" )
> MsgBox ">" & filename & "<"
> If fs.FileExists( filename ) Then
> fs.DeleteFile filename
> End If
>
> to check for whitespace. If there are leading or trailing blanks, use
>
> filename = Trim( rs( "field" ) )
>
> for other whitespace use (or ask for) a RegExp.
>
Quote:

> > I've tried to write out the filename, it show me a correct path and
> > filename to the path, whille i changed the filename to string "C:\path
> > \file" it works fine. however when i use a variable: filename, the
> > fileExist always return "false"
> >
> > anyone can tell me how to solve the problem?
> > thank you.
Interestingly enough, I found that trailing white space does not matter but
leading white space does. Also, it seems the .FileExists method does not
like the filespec to be quoted.

filename = Trim(Replace(filename, Chr(34), ""))

--
Todd Vargo
(Post questions to group only. Remove "z" to email personal messages)

My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
RegEx to return False if input is invalid. VB Script
Test-Path '' -IsValid does not return False but fails. Is this OK? PowerShell
How to return a specific type from a function PowerShell
return keyword in trap function PowerShell
Info: Can you Type a return from a function. PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46