Page 1 of 1
More path manipulation commands
Posted: Sun Feb 10, 2008 12:24 pm
by tinman
Hi,
In addition to GetExtensionPart(), GetFilePart() and GetPathPart() I'd like to see more commands for manipulating paths in an OS independant way.
AppendPath() - append one path onto another (making sure there are not two drives in the resulting path, taking care of directory separators etc).
RemovePart() - removes the last element from a path (either a directory or filename). Useful for navigating/finding to parent directories.
RemoveExtension() - remove the extension and the separator.
Apologies if this has already been requested, I searched but didn't find anything.
Posted: Sun Feb 10, 2008 12:28 pm
by Dare
+1 +1 +1
Re: More path manipulation commands
Posted: Sun Feb 10, 2008 12:40 pm
by PB
+1, and don't forget GetDrivePart() that I requested here:
http://www.purebasic.fr/english/viewtopic.php?t=30585
Posted: Tue Feb 12, 2008 11:25 pm
by NicTheQuick
+1
And it's not enough:
GetFilePartWithoutExtension() - returns the filename without extension
Code: Select all
Procedure.s GetFilePartWithoutExtension(File.s)
Protected *c.Character = @File, tmp.s = "", Result.s
While *c\c
If *c\c = '\'
tmp = ""
Result = ""
ElseIf *c\c = '.'
Result = tmp
tmp + Chr(*c\c)
Else
tmp + Chr(*c\c)
EndIf
*c + SizeOf(Character)
Wend
If Result
ProcedureReturn Result
Else
ProcedureReturn tmp
EndIf
EndProcedure
Debug GetFilePartWithoutExtension("C:\path\hi.hello.txt") ;"hi.hello"
Debug GetFilePartWithoutExtension("C:\path\hi.hello") ;"hi"
Debug GetFilePartWithoutExtension("C:\path\hi.hello\") ;""
Posted: Wed Feb 13, 2008 8:17 am
by PB
> GetFilePartWithoutExtension() - returns the filename without extension
Isn't that the same as the RemoveExtension() request?
Posted: Wed Feb 13, 2008 8:50 am
by NicTheQuick
I think RemoveExtension() returns the whole path + filename without
extension, isn't it?
Posted: Wed Feb 13, 2008 9:09 am
by Dare
So, without getting into command name details, and so we understand what we want (thus far) is this it?
* Append one path onto another.
Perhaps expand on this. Are we saying "C:\path\subpath\A\" 'appended with' "C:\path\subpath\B\" equals "C:\path\subpath\A\B\" or a straight drive-less concatenation "C:\path\subpath\A\path\subpath\B\")? Or something else?
* Remove the last logical element from a path, step by step would reduce it to just the drive.
-> "C:\path\subpath\A\myFile.exe"
-> "C:\path\subpath\A\"
-> "C:\path\subpath\"
-> "C:\path\subpath\"
-> "C:\path\"
-> "C:\"
With the file and extension being a logical element.
* Remove the extension and the separator from the path. (Leaving the path and the file)
-> "C:\path\subpath\A\myFile.exe"
-> "C:\path\subpath\A\myFile"
* Get the drive from a path.
-> "C:\path\subpath\A\myFile.exe"
-> "C:\"
* Get the file less extension.
-> "C:\path\subpath\A\myFile.exe"
-> "myFile"
Is this correct?
(Most of which we can do with stringfield or similar coding but dedicated commands would be quicker and easier to understand and "in context" - and in my case, less subject to error!)