Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Fussy check of cell contents | Excel Discussion (Misc queries) | |||
FileExists Example: | Excel Worksheet Functions | |||
Excel FileExists macro problem.... | Excel Programming |