spliting file name
-
i ma copying a file from a location to a destination but now i m unale to separate the file name that is come in with the whole path of the file please help me
make (for)loop that run in reverse searching for('\\')char then(break)
-
i ma copying a file from a location to a destination but now i m unale to separate the file name that is come in with the whole path of the file please help me
There are quite a few ways to do this, it will depend on what file information you have available. String: Use String.LastIndexOf to find the final '\' character, and String.Substring to extract just the file name. Or just use Path.GetFileName(string s) to extract it from any string. FileInfo: Use FileInfo.Name to extract just the file name. There are probably others, but these should cover most cases.
All those who believe in psycho kinesis, raise my hand. My :badger:'s gonna unleash hell on your ass. :badger:tastic!
-
make (for)loop that run in reverse searching for('\\')char then(break)
Why? There is a string.LastIndexOf method...
All those who believe in psycho kinesis, raise my hand. My :badger:'s gonna unleash hell on your ass. :badger:tastic!
-
i ma copying a file from a location to a destination but now i m unale to separate the file name that is come in with the whole path of the file please help me
Read up on the
Path
class; it holds everything you could want about file path strings. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]
-
i ma copying a file from a location to a destination but now i m unale to separate the file name that is come in with the whole path of the file please help me
You can do it one of two ways:
string[] pathParts = myPath.Split('\\');
and you'll end up with an array of strings that represent the various components. Or, you can use the various
System.Path.IO.GetXXXXX
methods..45 ACP - because shooting twice is just silly
-----
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001 -
Read up on the
Path
class; it holds everything you could want about file path strings. :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read code that is properly formatted, adding PRE tags is the easiest way to obtain that.
[The QA section does it automatically now, I hope we soon get it on regular forums as well]
That is the correct answer.