Jump to content

Path Related functions


Valik
 Share

Recommended Posts

Here are implementations of the C library functions splitpath, makepath and fullpath written in AutoIt.

  • _SplitPath: Splits a path into the drive, directory, file name and file extension parts. An empty string is set if a part is missing.
  • _MakePath: Creates a path from drive, directory, file name and file extension parts.
  • _FullPath: Creates a path based on the relative path you provide.
The code is commented and the parameters are explained in the source. Get it at this http://www.autoitscript.com/fileman/users/Valik/path.au3
Link to comment
Share on other sites

here are a few extras, since I like to have procedure calls to get the various parts on their own & use them to construct strings, plus one fn() to change a files extansion - useful for naming log files/backup files, etc

Btw, is there a web site anywhere which lists all fn()s & scraps which are available?

;===============================================================================

;

; Description: Given a fully qualified path name (such as one returned

; from _MakePath(), will return the volume part.

; Syntax: _GetVolumeFromFullPath( $fullPath )

; Parameter(s): $fullPath - fully qualified path name

; Requirement(s): None

; Return Value(s): volume part of given path

; Author(s): Graham Keellings software@Keellings.com

; Note(s): None

;

;===============================================================================

Func _GetVolumeFromFullPath( $fullPath )

Local $szDrive, $szDir, $szFName, $szExt

_SplitPath($fullPath, $szDrive, $szDir, $szFName, $szExt)

return $szDrive

EndFunc

;===============================================================================

;

; Description: Given a fully qualified path name (such as one returned

; from _MakePath(), will return the directory part.

; Syntax: _GetDirectoryFromFullPath( $fullPath )

; Parameter(s): $fullPath - fully qualified path name

; Requirement(s): None

; Return Value(s): directory part of given path

; Author(s): Graham Keellings software@Keellings.com

; Note(s): None

;

;===============================================================================

Func _GetDirectoryFromFullPath( $fullPath )

Local $szDrive, $szDir, $szFName, $szExt

_SplitPath($fullPath, $szDrive, $szDir, $szFName, $szExt)

return $szDir

EndFunc

;===============================================================================

;

; Description: Given a fully qualified path name (such as one returned

; from _MakePath(), will return the file name part.

; Syntax: _GetFileNameFromFullPath( $fullPath )

; Parameter(s): $fullPath - fully qualified path name

; Requirement(s): None

; Return Value(s): file name part of given path

; Author(s): Graham Keellings software@Keellings.com

; Note(s): None

;

;===============================================================================

Func _GetFileNameFromFullPath( $fullPath )

Local $szDrive, $szDir, $szFName, $szExt

_SplitPath($fullPath, $szDrive, $szDir, $szFName, $szExt)

return $szFName

EndFunc

;===============================================================================

;

; Description: Given a fully qualified path name (such as one returned

; from _MakePath(), will return the extension part.

; Syntax: _GetExtensionFromFullPath( $fullPath )

; Parameter(s): $fullPath - fully qualified path name

; Requirement(s): None

; Return Value(s): extension part of given path

; Author(s): Graham Keellings software@Keellings.com

; Note(s): None

;

;===============================================================================

Func _GetExtensionFromFullPath( $fullPath )

Local $szDrive, $szDir, $szFName, $szExt

_SplitPath($fullPath, $szDrive, $szDir, $szFName, $szExt)

return $szExt

EndFunc

;===============================================================================

;

; Description: Given a fully qualified path name (such as one returned

; from _MakePath(), will change the extension part as requested.

; Syntax: _ChangeFileExtension( $fullPath )

; Parameter(s): $fullPath - fully qualified path name

; $newExtension - nex extension

; Requirement(s): None

; Return Value(s): fully qualified path name with new extension

; Author(s): Graham Keellings software@Keellings.com

; Note(s): Useful for naming log files, backup files & otehr output files.

;

;===============================================================================

Func _ChangeFileExtension( $fullPath, $newExtension )

Local $szDrive, $szDir, $szFName, $szExt

_SplitPath($fullPath, $szDrive, $szDir, $szFName, $szExt)

return _MakePath($szPath, $szDrive, $szDir, $szFName, $newExtension)

EndFunc

Edited by graham
Link to comment
Share on other sites

Btw, is there a web site anywhere which lists all fn()s & scraps which are available?

that'd be pretty swank, a db of UDF's searchable on what it does, or what catagory it falls under... Anyone know if there's already server software for doing that?

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

very cool Valik, what do you think of having it check for and resolve UNC's?

Well, these functions don't stipulate that the path actually exist, only that it is or can be made into a valid path with the information provided. I stepped beyond the C versions of these functions when I made them compatible with UNC paths, but that's as far as I am taking them. The only validation of anything that could be added would be to ensure there are no illegal characters in the path (such as <>?*", et cetera). However, even the C versions don't support that, though, so I didn't, either. The first draft mimicked the C versions identically; I think it was requested UNC paths work so I added it. Otherwise, these functions are meant to be completely decoupled from the real filesystem in regards to existence/non-existence of one or more parts of the path.
Link to comment
Share on other sites

Well, these functions don't stipulate that the path actually exist, only that it is or can be made into a valid path with the information provided.  I stepped beyond the C versions of these functions when I made them compatible with UNC paths, but that's as far as I am taking them.  The only validation of anything that could be added would be to ensure there are no illegal characters in the path (such as <>?*", et cetera).  However, even the C versions don't support that, though, so I didn't, either.  The first draft mimicked the C versions identically; I think it was requested UNC paths work so I added it.  Otherwise, these functions are meant to be completely decoupled from the real filesystem in regards to existence/non-existence of one or more parts of the path.

ooohhh... they do support UNC... awesome, (this is me, blind) I wasn't meaning that they should check the path's validity (or that a server was up, etc) you already did it. awesome.

"I'm not even supposed to be here today!" -Dante (Hicks)

Link to comment
Share on other sites

  • 1 year later...
  • Developers

The link to path.au3 seems to be dead. Does anyone know where I can get this file?

<{POST_SNAPBACK}>

These UDFs are part of the File.au3 standard UDF lib.

Their names are now _PathFull,_PathMake,_PathSplit ..

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

These UDFs are part of the File.au3 standard UDF lib.

Their names are now _PathFull,_PathMake,_PathSplit ..

<{POST_SNAPBACK}>

Ups..this must be my old AutoIt. I've not used it in a long time and therefore I don't have the latest version :) Thanks for info!
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...