469,312 Members | 2,524 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

File Path validation without file creating functions

Hi,

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

Regards,

-aims

May 7 '07 #1
6 9019
>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
May 7 '07 #2
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

May 8 '07 #3
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

May 8 '07 #4
"Mohammad Omer" <mo******@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.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?
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
May 8 '07 #5
>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
May 8 '07 #6

"William DePalo [MVP VC++]" <wi***********@mvps.orgwrote in message
news:uJ**************@TK2MSFTNGP03.phx.gbl...
"Mohammad Omer" <mo******@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.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?

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.
>
Regards,
Will
www.ivrforbeginners.com


May 8 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Stefan Richter | last post: by
5 posts views Thread by hokiegal99 | last post: by
2 posts views Thread by Kenneth McDonald | last post: by
17 posts views Thread by Joe Laughlin | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.