File Path validation without file creating functions

  • Thread starter Thread starter Mohammad Omer
  • Start date Start date
M

Mohammad Omer

Hi,

I tried to validate file path without calling file creating functions.
Is it possible? How?

Regards,

-aims
 
I tried to validate file path without calling file creating functions.

How do you define "validate"?

Do you mean, the syntax is correct?
It's a path to a directory that exists?
It's a path and filename that I can open and read/write to?

Generally if you're going to need to do any file operation to it
subsequently, you may as well just do it.

Dave
 
Hi Dave ,

My path validation mean syntax validation, I tried a lot to find out
some way to check path validation without trying to create that path.
Let suppose
1) "C:\temp*2"
2) "D:\temp\abc\RE:Your File.txt"
all above paths are not valid.

Guide me, how I can validate path syntax?


Regards,
-aims
 
Hi Dave ,

My path validation mean syntax validation, I tried a lot to find out
some way to check path validation without trying to create that path.
Let suppose
1) "C:\temp*2"
2) "D:\temp\abc\RE:Your File.txt"
all above paths are not valid.

Guide me, how I can validate path syntax?


Regards,
-aims
 
Mohammad Omer said:
My path validation mean syntax validation, I tried a lot to find out
some way to check path validation without trying to create that path.
Let suppose
1) "C:\temp*2"
2) "D:\temp\abc\RE:Your File.txt"
all above paths are not valid.

Guide me, how I can validate path syntax?

I don't think that you can say definitively that a path is valid. Sure, you
can weed out some obvious invalid file paths, but the underlying file system
makes the final determination. So, what is valid on a local NTFS-formatted
disk may not be valid on a mapped network drive or on a optical device. What
is your ultimate objective, exactly?

Regards,
Will
www.ivrforbeginners.com
 
My path validation mean syntax validation, I tried a lot to find out
some way to check path validation without trying to create that path.
Let suppose
1) "C:\temp*2"
2) "D:\temp\abc\RE:Your File.txt"
all above paths are not valid.

Guide me, how I can validate path syntax?

As Will says, there's no guarantee, but maybe some of the Path* APIs
such as PathCleanupSpec(), PathFileExists(), PathGetCharType() may be
useful?

Dave
 
William DePalo said:
I don't think that you can say definitively that a path is valid. Sure,
you can weed out some obvious invalid file paths, but the underlying file
system makes the final determination. So, what is valid on a local
NTFS-formatted disk may not be valid on a mapped network drive or on a
optical device. What is your ultimate objective, exactly?

Not the OP, but to keep this moving:

Let's assume that this is some settings dialog, which stores configuration
parameters to some service or scheduled task, so the file access attempt
won't occur until much later, but you'd like to

In that case, a good first test can be made using a simple regular
expression.

In C++/Winapi however, this type of sanitization isn't needed -- you can
just wait for the actual file access to fail. However, for
languages/libraries with "smarts" built in to file access functions
(especially i/o redirection, etc) ala perl, bash, etc, sanitization is key
because otherwise you could potentially overwrite something important.
 
Here's what I use....

Function FolderExists(ByVal FolderInPath As String) As Boolean
Dim b As Boolean
If Len(Trim(FolderInPath)) = 0 Then
b = False
Else
Dim f As New System.IO.DirectoryInfo (FolderInPath)
b = f.Exists
End If
Return b
End Function

Brian Jasmer



Mohammad Omer wrote:

File Path validation without file creating functions
07-May-07

Hi

I tried to validate file path without calling file creating functions
Is it possible? How

Regards

-aims

EggHeadCafe - Software Developer Portal of Choice
WPF And The Model View View Model Pattern
http://www.eggheadcafe.com/tutorial...b-7374d3da3425/wpf-and-the-model-view-vi.aspx
 
Back
Top