Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
C++
int main()
{
  string filename="c:\\sample.png"//needs to validate the  filename with forbidden char

//here i m giving the filepath but it needs to escape the filepth& need to validate filename

// can any one help me how handle this situation 

}
Posted
Updated 8-May-14 12:16pm
v2
Comments
Maciej Los 8-May-14 18:21pm    
Is it one question?
Matt T Heffron 8-May-14 18:58pm    
What are you asking?
Do you want to know how to check if some string is a valid filepath and prevent the error/exception that would have occurred if it had been used?
Please use "Improve question" above to clarify.
Revising the title wouldn't hurt either...as it is, it reads as if you want to catch ALL Windows error message displays system-wide!
bijaynayak 9-May-14 3:06am    
I need to validate the filename.Ex: string filename="C:\\test.png".here filename is valid & needs to create the file in the respective directory,but due to "C:\\" it is treating as invalid filename.so how to handle in my application level.
Richard MacCutchan 9-May-14 5:21am    
There is nothing invalid in that string. You need to provide more details of exactly what happens when you run the program.
Matt T Heffron 9-May-14 13:11pm    
To follow on Richard's comment:
string filename = "C:\\test.png";
is a perfectly valid filename because the string will ACTUALLY contain: C:\test.png"
HOWEVER:
string filename = @"C:\\test.png";
is NOT a valid filename because the string will ACTUALLY contain: C:\\test.png"
The @ prefix turns off the escaping effect of the \ in the string.

1 solution

you can use the splitpath function to check for a valid path. And check the errno as described in the end.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900