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.
More path manipulation commands
- tinman
- PureBasic Expert
- Posts: 1102
- Joined: Sat Apr 26, 2003 4:56 pm
- Location: Level 5 of Robot Hell
- Contact:
More path manipulation commands
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
(WinXPhSP3 PB5.20b14)
Re: More path manipulation commands
+1, and don't forget GetDrivePart() that I requested here:
http://www.purebasic.fr/english/viewtopic.php?t=30585
http://www.purebasic.fr/english/viewtopic.php?t=30585
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
- NicTheQuick
- Addict
- Posts: 1504
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
+1
And it's not enough:
GetFilePartWithoutExtension() - returns the filename without extension
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\") ;""
- NicTheQuick
- Addict
- Posts: 1504
- Joined: Sun Jun 22, 2003 7:43 pm
- Location: Germany, Saarbrücken
- Contact:
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!)
* 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!)
Dare2 cut down to size