More path manipulation commands

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
tinman
PureBasic Expert
PureBasic Expert
Posts: 1102
Joined: Sat Apr 26, 2003 4:56 pm
Location: Level 5 of Robot Hell
Contact:

More path manipulation commands

Post 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.
If you paint your butt blue and glue the hole shut you just themed your ass but lost the functionality.
(WinXPhSP3 PB5.20b14)
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post by Dare »

+1 +1 +1
Dare2 cut down to size
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Re: More path manipulation commands

Post by PB »

+1, and don't forget GetDrivePart() that I requested here:
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.
User avatar
NicTheQuick
Addict
Addict
Posts: 1504
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Post 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\")    ;""
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> GetFilePartWithoutExtension() - returns the filename without extension

Isn't that the same as the RemoveExtension() request?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
User avatar
NicTheQuick
Addict
Addict
Posts: 1504
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Post by NicTheQuick »

I think RemoveExtension() returns the whole path + filename without
extension, isn't it?
Dare
Addict
Addict
Posts: 1965
Joined: Mon May 29, 2006 1:01 am
Location: Outback

Post 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!)
Dare2 cut down to size
Post Reply