Removing double dots from filename

the master
01-05-2008, 06:07 PM
Hi. Im not sure if there is a proper name for this (i dont know what to search on). I want to remove the double dots from a filename but in the same way windows would treat it.

"C:\test\folder\..\blah" would be "C:\test\blah"

I also want to check if there are too many double dots and if there are then ignore them.

"C:\test\..\..\.." would be "C:\"

dilettante
01-05-2008, 06:19 PM
GetFullPathName() in Kernel32 may resolve relative paths for you, but I haven't tried it.

JPB
01-05-2008, 08:33 PM
dilletante is correct, GetFullPathName API will resolve relative paths as you require.

the master
01-06-2008, 04:52 AM
That works perfect for filenames on the computer but this app also needs a remote filename which doesnt start with "C:\". When i try to use it on that filename it adds app.path to the begining of the filename before processing. Is there a way to handle part of a filename?

EG
"\webfolder\myfolder\..\..\..\.." should end up as "\webfolder" or at least "" (blank).

If not then i could add "C:\" to the begining of the path and remove it after processing

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum