Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default fso.FileExists is too fussy

I have this code...

Dim fso As Object, PathName as string

Set fso = CreateObject("Scripting.FileSystemObject")

PathName = c:\blahblah

If fso.FileExists(PathName) Then

Do this and that

This usally works a treat except that when the pathname
specified has a case change.

For example

If c:\Hello.doc exists

and I set PathName = c:\hello.doc

then the fso.FileExists function returns false.

Can anyone think of a workaround for this?

Thanks in advance for any answers

Nick Shinkins

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 340
Default fso.FileExists is too fussy

use the Dir() function to check for the file:

If Dir(PathName) < "" then
do this and that
end if

Robert Flanagan
Macro Systems
Delaware, U.S. 302-234-9857
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel

"Nick" wrote in message
...
I have this code...

Dim fso As Object, PathName as string

Set fso = CreateObject("Scripting.FileSystemObject")

PathName = c:\blahblah

If fso.FileExists(PathName) Then

Do this and that

This usally works a treat except that when the pathname
specified has a case change.

For example

If c:\Hello.doc exists

and I set PathName = c:\hello.doc

then the fso.FileExists function returns false.

Can anyone think of a workaround for this?

Thanks in advance for any answers

Nick Shinkins



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 102
Default fso.FileExists is too fussy

Nick wrote:

I have this code...

Dim fso As Object, PathName as string

Set fso = CreateObject("Scripting.FileSystemObject")

PathName = c:\blahblah

If fso.FileExists(PathName) Then

Do this and that

This usally works a treat except that when the pathname
specified has a case change.

For example

If c:\Hello.doc exists

and I set PathName = c:\hello.doc

then the fso.FileExists function returns false.

Can anyone think of a workaround for this?

Thanks in advance for any answers

Nick Shinkins


Excellent!
This means your code will also work on other, case-sensitive platforms.

No seriously, you could consider to use the (very old) dir function.
Try this:
Not(Dir(PathName) = "")
Should give the same result as fso.FileExists(PathName)

But please: post a followup here if you find a solution using only fso
and not dir.


--
Amedee Van Gasse using XanaNews 1.16.4.2
If it has an "X" in the name, it must be Linux?
Please don't thank me in advance. Thank me afterwards if it works or
hit me in the face if it doesn't. ;-)
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default fso.FileExists is too fussy

I'm sorry for wasting your time guys.

Just made a sheet with these fields

L:\Clients\ACTUARY\Nick\Programs\VALDATB\hello.dat
L:\Clients\ACTUARY\Nick\Programs\VALDATB\Hello.dat
L:\Clients\ACTUARY\Nick\Programs\VALDATB\hello.DAT
L:\Clients\ACTUARY\Nick\Programs\VALDATB\Hello.DAT

and tested for the existance of the file in each case with
the fso object.

It came back true in each case which means the error is
somewhere else in my program.

Therefore everyone should use the fso object since it is
fast and concise. And not too fussy.

Thanks again for your answers - which were perfectly good.

Nick Shinkins
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default fso.FileExists is too fussy

If that ever works, then it must because you have a file with that name - it
doesn't work for a folder (at least not in Win 2000). You need to use
FolderExists to check for a folder:

Sub Tester1()
Dim fso As Object, PathName As String

Set fso = CreateObject("Scripting.FileSystemObject")

PathName = "c:\data\"

If fso.FolderExists(PathName) Then
MsgBox PathName & " exists"
Else
MsgBox PathName & " does not exist"
End If

End Sub

and that isn't case sensitive.

--
Regards,
Tom Ogilvy

"Nick" wrote in message
...
I have this code...

Dim fso As Object, PathName as string

Set fso = CreateObject("Scripting.FileSystemObject")

PathName = c:\blahblah

If fso.FileExists(PathName) Then

Do this and that

This usally works a treat except that when the pathname
specified has a case change.

For example

If c:\Hello.doc exists

and I set PathName = c:\hello.doc

then the fso.FileExists function returns false.

Can anyone think of a workaround for this?

Thanks in advance for any answers

Nick Shinkins





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default fso.FileExists is too fussy

Guess you threw me off with your pathname variable.

FileExists is case insensitive as well as it appears you have discovered
yourself.

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
If that ever works, then it must because you have a file with that name -

it
doesn't work for a folder (at least not in Win 2000). You need to use
FolderExists to check for a folder:

Sub Tester1()
Dim fso As Object, PathName As String

Set fso = CreateObject("Scripting.FileSystemObject")

PathName = "c:\data\"

If fso.FolderExists(PathName) Then
MsgBox PathName & " exists"
Else
MsgBox PathName & " does not exist"
End If

End Sub

and that isn't case sensitive.

--
Regards,
Tom Ogilvy

"Nick" wrote in message
...
I have this code...

Dim fso As Object, PathName as string

Set fso = CreateObject("Scripting.FileSystemObject")

PathName = c:\blahblah

If fso.FileExists(PathName) Then

Do this and that

This usally works a treat except that when the pathname
specified has a case change.

For example

If c:\Hello.doc exists

and I set PathName = c:\hello.doc

then the fso.FileExists function returns false.

Can anyone think of a workaround for this?

Thanks in advance for any answers

Nick Shinkins





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default fso.FileExists is too fussy

I'm afraid the problem was merely my lack of good
programming skills.

I quickly decided that the fso object was the problem when
actually one of the employees had kindly changed the name
of a folder ever so slightly.

I just needed to look more closely. Maybe caffeine will
help :)

Thanks for looking into it for me.

Nick Shinkins


-----Original Message-----
Guess you threw me off with your pathname variable.

FileExists is case insensitive as well as it appears you

have discovered
yourself.

--
Regards,
Tom Ogilvy

"Tom Ogilvy" wrote in message
...
If that ever works, then it must because you have a

file with that name -
it
doesn't work for a folder (at least not in Win 2000).

You need to use
FolderExists to check for a folder:

Sub Tester1()
Dim fso As Object, PathName As String

Set fso = CreateObject("Scripting.FileSystemObject")

PathName = "c:\data\"

If fso.FolderExists(PathName) Then
MsgBox PathName & " exists"
Else
MsgBox PathName & " does not exist"
End If

End Sub

and that isn't case sensitive.

--
Regards,
Tom Ogilvy

"Nick" wrote in

message
...
I have this code...

Dim fso As Object, PathName as string

Set fso = CreateObject("Scripting.FileSystemObject")

PathName = c:\blahblah

If fso.FileExists(PathName) Then

Do this and that

This usally works a treat except that when the

pathname
specified has a case change.

For example

If c:\Hello.doc exists

and I set PathName = c:\hello.doc

then the fso.FileExists function returns false.

Can anyone think of a workaround for this?

Thanks in advance for any answers

Nick Shinkins





.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Fussy check of cell contents access_mk Excel Discussion (Misc queries) 1 April 19th 06 01:28 PM
FileExists Example: El Bee Excel Worksheet Functions 0 February 15th 06 09:19 PM
Excel FileExists macro problem.... Inabus Excel Programming 3 August 26th 04 10:44 AM


All times are GMT +1. The time now is 04:54 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"