Board index » cppbuilder » Clean up my filepath

Clean up my filepath


2006-02-15 03:14:19 PM
cppbuilder0
Hi all,
I have a string containing path and name of a file, like this:
"C:\Dir1\Dir2\Dir3\..\..\SomeFile.ext". The path is correct and
I can access the file, but I would like to clean up the path for
diplay, i.e.: "C:\Dir1\SomeFile.ext". I know it wouldn't be to
hard to do the string manipulations myself, but I am too lazy
and also quite curious if I could just ask the system for the
clean path. Is there a command or a series of commands that
gives/give me the cleaned up path?
 
 

Re:Clean up my filepath

Quote
I have a string containing path and name of a file, like this:
"C:\Dir1\Dir2\Dir3\..\..\SomeFile.ext". The path is correct
Not sure I understood, but have a look at PathCompactPath:
msdn.microsoft.com/library/default.asp
Stefano.
 

Re:Clean up my filepath

Also look at BCB6/VCL Help for MinimizeName()
--
Best regards,
Vladimir Stefanovic
 

{smallsort}

Re:Clean up my filepath

"Thorsten Kettner" wrote something like:
Quote
Convert path "C:\Dir1\Dir2\Dir3\..\..\SomeFile.ext" to
"C:\Dir1\SomeFile.ext".
Thank you Stefano and Vladimir. I am not looking for functions
that truncate my path to fit in a given pixel width, but I am
glad though you mentioned the functions for two reasons. First:
You pointed me to PathCompactPath. That made me look at shlwapi
path functions. Thus I found PathCanonicalize, which is what I
had been looking for. Second: I didn't know about MinimizeName
and PathCompactPath and coded something alike in another project
which I can replace now by a mere function call.
Explanation of what I was looking for:
The path "C:\Dir1\Dir2\Dir3\..\..\SomeFile.ext" means exactly
the same as "C:\Dir1\SomeFile.ext", because "\.." means: go up
one directory. If one interprets the path to find out where
SomeFile.ext is located, it goes like this: Go to C:\, then go
down to Dir1, then down to Dir2, then down to Dir3, then one
dir up (to Dir2), then one dir up (to Dir1). I wanted the system
to state that the path "C:\Dir1\Dir2\Dir3\..\..\SomeFile.ext"
means nothing else but simply "C:\Dir1\SomeFile.ext".
 

Re:Clean up my filepath

Quote
Explanation of what I was looking for:
The path "C:\Dir1\Dir2\Dir3\..\..\SomeFile.ext" means exactly
the same as "C:\Dir1\SomeFile.ext", because "\.." means: go up
Right. I had to pay more attention to the paths you wrote, while
I thought they were just examples. Happy you solved now.
Stefano.