PathName:
Filter:
Classes | Files

PathName : Object

file and directory path utilities
Source: PathName.sc

Description

PathName is a utility class for manipulating file names and paths. It expects a path to a file, and lets you access parts of that file path.

Class Methods

PathName.new(path: "")

Arguments:

path

a String which likely contains one or more / as typical for folder separation. ~ will be converted to your fully addressed home directory, as per String: -standardizePath.

PathName.tmp

PathName.tmp = value

Get or set the global temp directory as a String. This is used by Buffer, etc. By default this is "/tmp/" for Linux and macOS, and "/WINDOWS/TEMP/" for Windows.

Inherited class methods

Undocumented class methods

PathName.scroot

PathName.scroot = value

Instance Methods

.fileName

returns just the name of the file itself; i.e. everything after the last slash in the full path.

.fileNameWithoutExtension

returns the name of the file itself without the file extension.

.extension

returns the file extension, i.e. everything after the last full-stop in the -fileName.

.pathOnly

returns the full path up to the file name itself; i.e. everything up to and including the last slash. This is handy e.g. for storing several files in the same folder.

.isAbsolutePath

.asAbsolutePath

.isRelativePath

.asRelativePath(relativeTo)

you MUST have correctly initialized the scroot classvar for this to know what it is relative to !

.folderName

returns only the name of the folder that the file is in; i.e. everything in between the last but one and the last slash.

.fullPath

returns the full path name that PathName contains.

.entries

returns a list of all the files+folders inside the folder represented by this path.

.files

returns a list of all the files in the folder represented by this path.

.folders

returns a list of all the subfolders of the folder represented by this path.

.isFile

returns a Boolean indicating whether or not the path represents a file (not a folder).

.isFolder

returns a Boolean indicating whether or not the path represents a folder (not a file).

.filesDo(func)

Iterates over all files found in the pathname, including ones in subfolders.

.allFolders

returns a list of all the folder names contained in the pathname itself.

.diskName

if path is an absolute path, returns the disk name; else a blank string.

+/+(path)

Path concatenation operator - useful for avoiding doubling-up slashes unnecessarily.

.endNumber

returns a number at the end of PathName. Returns zero if there is no number.

.noEndNumbers

returns -fullPath without any numbers at the end.

.nextName

generates a sensible next name for a file by incrementing a number at the end of PathName, or by adding one if there is none. This is useful for recording files with consecutive names, and e.g. to generate a new filename when you don't want to overwrite an existing file with the current name.

Inherited instance methods

Undocumented instance methods

.absolutePath

.colonIndices

.deepFiles

.dumpToDoc(title: "Untitled")

.dumpTree

.endNumberIndex

.fileNameWithoutDoubleExtension

.lastColonIndex

.parentPath

.pathMatch

.streamTree(str, tabs: 0)

Examples

Here is an example that uses many instance methods. Just pick any file to see all the parts of its path.

Choose a soundfile to put into the library, using its foldername and filename.

Save three tables in the same folder. Note: The file name chosen in the dialog is ignored! The files are always named table1, table2, table3.