473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

question about file.exists and wildcards

Lou
Question:

I can't seem to get file.exists(filename) to return true when I search using
wildcards, and I know there's a file in that dir with that extension.
here's the path
dim yesno as boolean
FileName = "D:\Documents and Settings\Lou\My Documents\Visual Studio
Projects\Lucky7\Lucky7\bin\*.txt"

yesno=file.exists(filename)

file.exists keeps returning false when there is a readme.txt file in that dir.

It works if I explicitly name the file but not with the wildcard.
so...what am I doing wrong?
Thanks for helping this noobie.
Feb 4 '06 #1
3 19720
Hi Lou,

The File.Exists(string) method takes a file path as an argument. It does not
support using wildcards, because it is used to determine whether or not a
single file having the file name exists at the location specified. Wildcard
searches return multiple files. The Directory.GetFiles(string, string)
method will return an array of file paths for files in a Directory which
match the search pattern specified. The first argument is the path to the
directory, and the second is the search pattern. If there are no matching
files, the array will be empty.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Lou" <Lo*@discussions.microsoft.com> wrote in message
news:9F**********************************@microsof t.com...
Question:

I can't seem to get file.exists(filename) to return true when I search
using
wildcards, and I know there's a file in that dir with that extension.
here's the path
dim yesno as boolean
FileName = "D:\Documents and Settings\Lou\My Documents\Visual Studio
Projects\Lucky7\Lucky7\bin\*.txt"

yesno=file.exists(filename)

file.exists keeps returning false when there is a readme.txt file in that
dir.

It works if I explicitly name the file but not with the wildcard.
so...what am I doing wrong?
Thanks for helping this noobie.

Feb 4 '06 #2
You cannot use wildchar search with filenames. The only solution to this is
to use Directory.GetFiles(path, "*.txt"); This returns a list of files which
will match the criteria and you can then enumerate them.
You statement is ABSOLUTLY wrong.
Thanks
--
Shrinivas Reddy.
Systems Analyst
Satyam Computer Services Ltd.
"Lou" wrote:
Question:

I can't seem to get file.exists(filename) to return true when I search using
wildcards, and I know there's a file in that dir with that extension.
here's the path
dim yesno as boolean
FileName = "D:\Documents and Settings\Lou\My Documents\Visual Studio
Projects\Lucky7\Lucky7\bin\*.txt"

yesno=file.exists(filename)

file.exists keeps returning false when there is a readme.txt file in that dir.

It works if I explicitly name the file but not with the wildcard.
so...what am I doing wrong?
Thanks for helping this noobie.

Feb 4 '06 #3
> You statement is ABSOLUTLY wrong.

Which "statement?" He was asking a question. Jeez. No need to hammer an
admitted "noobie."

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Who is Mighty Abbott?
A twin turret scalawag.

"Sinu" <Si**@discussions.microsoft.com> wrote in message
news:02**********************************@microsof t.com...
You cannot use wildchar search with filenames. The only solution to this
is
to use Directory.GetFiles(path, "*.txt"); This returns a list of files
which
will match the criteria and you can then enumerate them.
You statement is ABSOLUTLY wrong.
Thanks
--
Shrinivas Reddy.
Systems Analyst
Satyam Computer Services Ltd.
"Lou" wrote:
Question:

I can't seem to get file.exists(filename) to return true when I search
using
wildcards, and I know there's a file in that dir with that extension.
here's the path
dim yesno as boolean
FileName = "D:\Documents and Settings\Lou\My Documents\Visual Studio
Projects\Lucky7\Lucky7\bin\*.txt"

yesno=file.exists(filename)

file.exists keeps returning false when there is a readme.txt file in that
dir.

It works if I explicitly name the file but not with the wildcard.
so...what am I doing wrong?
Thanks for helping this noobie.

Feb 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Joseph Oget | last post by:
If I use the code below in a VB.NET form, even if the file exists, and is then executed, the Else statement produces the "Sorry cannot find the File " error message. The MessageBox.Show(...
10
by: Raymond | last post by:
Hi All: To find a file exists using the file name, I have tow routings on UNIX system. 1. access(2) 2. lstat(2) This tow function also can do. When the return value is "-1" and errno is...
18
by: Dan | last post by:
I have code like the following to test for existence of a file. I know the file is there, but File.Exists returns FALSE. The problem appears to be that the file is in a directory beneath "My...
2
by: Chris Fink | last post by:
I am using the System.IO.File class to determine if a file exists on a network share. The File.Exists method keeps returning false, even though the file does exist. The MSDN documentation...
6
by: John Dann | last post by:
I need to check whether there are _any_ (ie one or more) files of a specified file type in a folder. Will: if file.exists(path & "*.typ") then ... work reliably? If not then what's the best...
2
by: =?Utf-8?B?R29yZG9u?= | last post by:
Hi; What is the correct syntax for checking for a file's existence based on it's extension ? Example: Imports system.io Dim path as string = "C:\myDirectory\*.txt"
10
by: Julia | last post by:
Hi, there, I am trying to append a binary file by using: FILE *strean; stream = fopen( "c:\temp.dat", "ba+" )); Is there a way that I can check if the file exists or not before fopen,...
7
by: sprash | last post by:
Newbie question: I'm trying to determine if a file physically exists regardless of the permissions on it Using File.Exists() returns false if it physically exists but the process does not...
8
by: Sweetiecakes | last post by:
In our series of "probably something simple"... I am doing a File.Exists operation to check if a file exists. Let's assume that this file is C:/test.txt. Now, if I do...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.