String Parsing in C++ (Simple Question)
-
Hi All I have this string /work1/data/xxxx/yyy/file_name.txt how to extract "only" the path name without the file name in C++ thanks
-
Try out splitpath API, it will meet your requirement, check out MSDN for the syntax Thanx
-
you need to create your own function for this. go ahead and try it. if you are stuck ask for help.
-
Tried boost tokenizer[^]? :)
Navaneeth How to use google | Ask smart questions
-
Hi All I have this string /work1/data/xxxx/yyy/file_name.txt how to extract "only" the path name without the file name in C++ thanks
Use the following line of code.
dirPath =fullFilePath.substr(0,(fullFilePath.find_last_of(L"\\")));
Prafulla Vedante
-
Hi All I have this string /work1/data/xxxx/yyy/file_name.txt how to extract "only" the path name without the file name in C++ thanks
traverse the char array from end (in reverse way) till you see a / and then replace '\0' there.
-------------------------------------------- Suggestion to the members: Please prefix your main thread subject with [SOLVED] if it is solved. thanks. chandu.
-
Hi All I have this string /work1/data/xxxx/yyy/file_name.txt how to extract "only" the path name without the file name in C++ thanks
const char * path = "/work1/data/xxxx/yyy/file_name.txt";
const char * filename;
filename = path+strlen(path);
while (filename != path && *(filename) != '/')
filename--;
if ( filename != path) filename++;:)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi All I have this string /work1/data/xxxx/yyy/file_name.txt how to extract "only" the path name without the file name in C++ thanks
If you want simple hack, then
std::string s = "/work1/data/xxxx/yyy/file_name.txt";
std::string::size_type lastSep = s.find_last_of('/');
if (lastSep != std::string::npos)
s.erase(lastSep);If you want a nice cross-platform for manipulating file paths, I'll recommend Boost.FileSystem[^], where you can do this:
boost::filesystem::path justThePath("/work1/data/xxxx/yyy/file_name.txt");
justThePath.remove_filename();Oh - and it'll happily deal with Windows vs Unix path conventions.
Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p
-
Hi All I have this string /work1/data/xxxx/yyy/file_name.txt how to extract "only" the path name without the file name in C++ thanks
ksaw123 wrote:
how to extract "only" the path name without the file name in C++
Have you tried
PathRemoveFileSpec()
?"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons