/usr/share/SuperCollider/HelpSource/Classes/PathName.schelp is in supercollider-common 1:3.8.0~repack-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 | class:: PathName
summary:: file and directory path utilities
related:: Classes/File, Classes/String
categories:: Files
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.
ClassMethods::
private::initClass
method::new
argument::path
a link::Classes/String:: which likely contains one or more / as typical for folder separation. ~ will be converted to your fully addressed home directory, as per link::Classes/String#-standardizePath::.
code::
PathName.new("MyDisk/SC 2.2.8 f/Sounds/FunkyChicken");
::
method::tmp
Get or set the global temp directory as a link::Classes/String::. This is used by link::Classes/Buffer::, etc. By default this is "/tmp/" for Linux and OSX, and "/WINDOWS/TEMP/" for Windows.
InstanceMethods::
method::fileName
returns just the name of the file itself; i.e. everything after the last slash in the full path.
code::
(
var myPath;
myPath = PathName.new("MyDisk/SC 2.2.8 f/Sounds/FunkyChicken");
myPath.fileName.postln;
)
::
method:: fileNameWithoutExtension
returns the name of the file itself without the file extension.
method::extension
returns the file extension, i.e. everything after the last full-stop in the link::#-fileName::.
method::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.
code::
(
var myPath;
myPath = PathName.new("MyDisk/SC 2.2.8 f/Sounds/FunkyChicken");
myPath.pathOnly.postln;
)
::
method::isAbsolutePath, asAbsolutePath, isRelativePath, asRelativePath
you MUST have correctly initialized the scroot classvar for this to know what it is relative to !
method::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.
code::
(
var myPath;
myPath = PathName.new("MyDisk/SC 2.2.8 f/Sounds/FunkyChicken");
myPath.folderName.postln;
)
::
method::fullPath
returns the full path name that PathName contains.
code::
(
var myPath;
myPath = PathName.new("MyDisk/SC 2.2.8 f/Sounds/FunkyChicken");
myPath.fullPath.postln;
)
::
method::entries
returns a list of all the files+folders inside the folder represented by this path.
code::
(
var myPath;
myPath = PathName.new("./");
myPath.entries.postln;
)
::
method::files
returns a list of all the files in the folder represented by this path.
code::
(
var myPath;
myPath = PathName.new("./");
myPath.files.postln;
)
::
method::folders
returns a list of all the subfolders of the folder represented by this path.
code::
(
var myPath;
myPath = PathName.new("./");
myPath.folders.postln;
)
::
method::isFile
returns a link::Classes/Boolean:: indicating whether or not the path represents a file (not a folder).
code::
(
var myPath;
myPath = PathName.new("./");
myPath.isFile.postln;
)
::
method::isFolder
returns a link::Classes/Boolean:: indicating whether or not the path represents a folder (not a file).
code::
(
var myPath;
myPath = PathName.new("./");
myPath.isFolder.postln;
)
::
method::filesDo
Iterates over all files found in the pathname, including ones in subfolders.
code::
(
var myPath;
myPath = PathName.new("./");
myPath.filesDo{|afile| afile.postln};
)
::
method::allFolders
returns a list of all the folder names contained in the pathname itself.
code::
(
var myPath;
myPath = PathName.new("MyDisk/SC 2.2.8 f/Sounds/FunkyChicken");
myPath.allFolders.postln;
)
::
method::diskName
if path is an absolute path, returns the disk name; else a blank string.
code::
(
var myPath;
myPath = PathName.new("MyDisk/SC 2.2.8 f/Sounds/FunkyChicken");
myPath.diskName.postln;
)
( // note the / at the start
var myPath;
myPath = PathName.new("/MyDisk/SC 2.2.8 f/Sounds/FunkyChicken");
myPath.diskName.postln;
)
::
method::+/+
Path concatenation operator - useful for avoiding doubling-up slashes unnecessarily.
code::
(PathName("/somewhere") +/+ PathName("over/the/rainbow")).postln;
(PathName("/somewhere") +/+ PathName("/over/the/rainbow")).postln;
::
method::endNumber
returns a number at the end of PathName. Returns zero if there is no number.
code::
PathName("floating1").endNumber.postln;
PathName("floating").endNumber.postln;
::
method::noEndNumbers
returns link::#-fullPath:: without any numbers at the end.
code::
PathName("floating1").noEndNumbers.postln;
PathName("floating").noEndNumbers.postln;
::
method::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.
code::
PathName("floating34").nextName.postln;
PathName("floating").nextName.postln;
PathName("floating12_3A4X_56.7").nextName.postln;
::
Examples::
Here is an example that uses many instance methods. Just pick any file to see all the parts of its path.
code::
(
GetFileDialog.new(
{ arg ok, path;
var myPathName;
if (ok,
{
myPathName = PathName.new(path);
"New PathName object: ".postc;
myPathName.postln;
"fileName only: ".postc;
myPathName.fileName.postln;
"path up to file only: ".postc;
myPathName.pathOnly.postln;
"folder Name: ".postc;
myPathName.folderName.postln;
}
)
}
)
)
::
Choose a soundfile to put into the library, using its foldername and filename.
code::
(
GetFileDialog.new(
{ arg ok, path;
var myPathName, myFile;
if (ok,
{
myPathName = PathName.new(path);
// read your file from disk, e.g. a soundFile/
myFile = SoundFile.new;
if (myFile.openRead(path),
{
Library.put(
[ myPathName.folderName.asSymbol, myPathName.fileName.asSymbol ],
myFile);
("Check Library.global" + myPathName.folderName + "please.").postln;
},
{ ("Could not read soundfile" + path ++ ".").postln; }
);
myFile.close;
}
)
}
)
)
::
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.
code::
(
var table1, table2, table3;
table1 = Wavetable.sineFill(1024, [1,2,3]);
table2 = Signal.newClear.asWavetable;
table3 = Wavetable.sineFill(1024, Array.rand(64, 0.0, 1.0));
GetFileDialog.new(
{ arg ok, path;
var myPathName, myPathOnly;
if (ok,
{
myPathName = PathName.new(path);
myPathOnly = myPathName.pathOnly;
("writing files tables1-3 to"+myPathOnly).postln;
table1.write(myPathOnly ++ "table1");
table2.write(myPathOnly ++ "table2");
table3.write(myPathOnly ++ "table3");
}
)
}
)
)
::
|