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

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 9235
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
5
by: hokiegal99 | last post by:
A few questions about the following code. How would I "wrap" this in a function, and do I need to? Also, how can I make the code smart enough to realize that when a file has 2 or more bad...
2
by: Kenneth McDonald | last post by:
I'd like to propose a new PEP , for a standard library module that deals with files and file paths in an object oriented manner. I believe this module should be included as part of the standard...
17
by: Joe Laughlin | last post by:
I've not used C much before, so I don't know how robust or good this code is. I'd appreciate any feedback or criticisms anyone has! Thanks, Joe #include <stdio.h> #include <string.h>
7
by: TLM | last post by:
I am trying to build a web application that will contain links to files on a users local computer. I am assuming that the files will be in a known location and can display in a browser window. ...
1
by: Kum | last post by:
Hi, I need help in asp.net dynamic textbox controls validation. I am creating textbox controls dynamically on a asp.net webpage. Now after creating the textboxes on the page I want to validate...
10
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the...
65
by: Hongyu | last post by:
Dear all: I am trying to write to a file with full directory name and file name specified (./outdir/mytestout.txt where . is the current directory) in C programming language and under Unix, but...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.