By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,446 Members | 2,998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,446 IT Pros & Developers. It's quick & easy.

File Path validation without file creating functions

P: n/a
Hi,

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

Regards,

-aims

May 7 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
>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

P: n/a
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

P: n/a
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

P: n/a
"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

P: n/a
>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

P: n/a

"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.