473,785 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9261
>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.goo glegroups.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******** ******@TK2MSFTN GP03.phx.gbl...
"Mohammad Omer" <mo******@gmail .comwrote in message
news:11******** **************@ p77g2000hsh.goo glegroups.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
3924
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 adresses and so on. I thought it might be a better way to programm an automated, dynamic form validation that works for all kinds of fields, shows the necessary error messages and highlights the coresponding form fields.
5
3348
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 charcters in it, that the code needs to run until all bad characters are gone? For example, if a file has the name "<bad*mac\file" the program has to run 3 times to get all three bad chars out of the file name. The passes look like this:
2
1848
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 Python distribution. Background ========== Some time ago, I wrote such a module for myself, and have found it extremely useful. Recently, I found a reference to a similar module, http://www.jorendorff.com/articles/python/path/ by Jeff Orendorff.
17
2334
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
6395
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. I have my ASP.NET application building links along the lines of file://c:/<path to file>
1
1964
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 these text boxes when the user submits or posts back to the server. My intention was to create a textboxvalidator function which takes the control name as argument and returns an true if
10
5724
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 form the control is on? Basically I have a number of controls in a form that are required, and to check it I am setting the Validation Rule to "<>"IsNull" so that when the user tries to tab through/click out of a required area without entering...
65
5104
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 got errors of Failed to open file ./outdir/mytestout.txt. Below is the code: #include <stdio.h>
1
47488
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 on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9645
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10155
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.