Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

File Path validation without file creating functions

0 views
Skip to first unread message

Mohammad Omer

unread,
May 7, 2007, 1:55:19 AM5/7/07
to
Hi,

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

Regards,

-aims

David Lowndes

unread,
May 7, 2007, 4:20:19 AM5/7/07
to
>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

Mohammad Omer

unread,
May 8, 2007, 12:45:52 AM5/8/07
to
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

unread,
May 8, 2007, 12:46:09 AM5/8/07
to

William DePalo [MVP VC++]

unread,
May 8, 2007, 1:50:42 AM5/8/07
to
"Mohammad Omer" <mome...@gmail.com> wrote in message
news:1178599552.7...@p77g2000hsh.googlegroups.com...

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


David Lowndes

unread,
May 8, 2007, 5:31:48 AM5/8/07
to

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

Dave

Ben Voigt

unread,
May 8, 2007, 9:36:50 AM5/8/07
to

"William DePalo [MVP VC++]" <willd....@mvps.org> wrote in message
news:uJDvRTTk...@TK2MSFTNGP03.phx.gbl...

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.

>
> Regards,
> Will
> www.ivrforbeginners.com
>
>


brianjasmer

unread,
Sep 24, 2009, 4:06:24 PM9/24/09
to
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,

Regards,

-aims

EggHeadCafe - Software Developer Portal of Choice
WPF And The Model View View Model Pattern
http://www.eggheadcafe.com/tutorials/aspnet/ec832ac7-6e4c-4ea8-81ab-7374d3da3425/wpf-and-the-model-view-vi.aspx

0 new messages