473,383 Members | 1,862 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,383 software developers and data experts.

check if file path is valid

Hello All -

Is there a way to check if a file path string is valid? I.e. is there
a function that takes some string, say 'c:\somedir\subdir' and returns
TRUE if it is valid or FALSE if no such path exists?

Thanks!
Brian
Nov 20 '05 #1
6 28761
On 2003-11-21, dave <th*****@mailcity.com> wrote:
Hello All -

Is there a way to check if a file path string is valid? I.e. is there
a function that takes some string, say 'c:\somedir\subdir' and returns
TRUE if it is valid or FALSE if no such path exists?

Thanks!
Brian


Imports System.IO

....

If Directory.Exists("c:\my directory") Then
...
End If

If File.Exists("C:\my directory\myfile.txt") Then
....
End If

--
Tom Shelton
[MVP - Visual Basic]
Nov 20 '05 #2
* th*****@mailcity.com (dave) scripsit:
Is there a way to check if a file path string is valid? I.e. is there
a function that takes some string, say 'c:\somedir\subdir' and returns
TRUE if it is valid or FALSE if no such path exists?


'System.IO.Directory.Exists'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #3
On 21 Nov 2003 10:53:51 -0800, dave <th*****@mailcity.com> wrote:
Hello All -

Is there a way to check if a file path string is valid? I.e. is there
a function that takes some string, say 'c:\somedir\subdir' and returns
TRUE if it is valid or FALSE if no such path exists?

Thanks!
Brian


This used to work in VB6, I havn't tried it in .NET yet.....

if dir$("C:\Myfile.xxx")="" then 'the file does not exist

if it does exist, it returns the filename back to you.

Scott
Nov 20 '05 #4
On 21 Nov 2003 10:53:51 -0800, dave <th*****@mailcity.com> wrote:
Hello All -

Is there a way to check if a file path string is valid? I.e. is there
a function that takes some string, say 'c:\somedir\subdir' and returns
TRUE if it is valid or FALSE if no such path exists?

Thanks!
Brian


This used to work in VB6, I havn't tried it in .NET yet.....

if dir$("C:\Myfile.xxx")="" then 'the file does not exist

if it does exist, it returns the filename back to you.

Scott
Nov 20 '05 #5
* Scott Hather <x@y.com> scripsit:
Is there a way to check if a file path string is valid? I.e. is there
a function that takes some string, say 'c:\somedir\subdir' and returns
TRUE if it is valid or FALSE if no such path exists?


This used to work in VB6, I havn't tried it in .NET yet.....

if dir$("C:\Myfile.xxx")="" then 'the file does not exist

if it does exist, it returns the filename back to you.


This code has some disadvantages in VB6, it should not be used to check
if a file exists.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
* Scott Hather <x@y.com> scripsit:
Is there a way to check if a file path string is valid? I.e. is there
a function that takes some string, say 'c:\somedir\subdir' and returns
TRUE if it is valid or FALSE if no such path exists?


This used to work in VB6, I havn't tried it in .NET yet.....

if dir$("C:\Myfile.xxx")="" then 'the file does not exist

if it does exist, it returns the filename back to you.


This code has some disadvantages in VB6, it should not be used to check
if a file exists.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #7

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

Similar topics

27
by: mrbog | last post by:
Tell me if my assertion is wrong here: The only way to prevent session hijacking is to NEVER store authentication information (such as name/password) in the session. Well, to never authenticate...
9
by: Maciej Sobczak | last post by:
Hi, I have a string. This string is to be used as a path for a new file. I would like to check if this string *could be* a valid file name, *before* I try to create the file itself. In other...
2
by: David Fickbohm | last post by:
People, I am trying to determine the creation date of files in a folder. I am using the following code to find the folder and confirm that files exist in the folder. If someone could give me an...
4
by: Henry Jia | last post by:
Hi, Does there has any easy way to check if a specified url is a valid one (both the format should be valid but also the specified path / file is available)? Thanks in advance! Henry
2
by: MikeY | last post by:
Hi all, I am coding window forms in C#. My problem is this: I have created a "Check ListView" or a 'ListView' with checkbox's. I have populated the it with my files from my folders, mps, txt,...
19
by: Noozer | last post by:
I need to keep my application settings in a file that users can copy/backup/etc. Before I start using the old INI file standard, is there any easy way to use XML files to hold application...
24
by: dancer | last post by:
Using ASP.net 1.1 and Microsoft Access. I received the following error message. Why? I have closed the Access file. I have another very small access file that opens with no trouble with the...
10
by: Academia | last post by:
I'd like to check a string to see that it is a valid file name. Is there a Like pattern or RegEx that can do that. 1) Just the file name with maybe an extension 2)A full path An help...
2
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 but can upgrade if necessary. Given a path to a file on my server, is there a way I can check if that file is of a PDF format? I'm guessing the answer to this may...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?

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.