Home
Martin Koch edited this page Aug 20, 2022
·
33 revisions
The Path repo consists of the two classes File
and Folder
which represent file and folder paths, respectively.
Construct File
and Folder
objects by providing the constructors with one or multiple arguments of type string
vector, char
vector, cell
of string
or char
vectors. The paths may contain path separator characters.
Example:
>> files = File(["models\FlyingCar.slx", "models\DrivingPlane.slx", "..\Docs\StateSecrets.pdf", "C:\Skynet.exe"])
File("models\FlyingCar.slx")
File("models\DrivingPlane.slx")
File("..\Documents\StateSecrets.pdf")
File("C:\Skynet.exe")
The objects allow you to use the methods listed below.
Example:
>> files.where(Extension=".slx").stem
"FlyingCar" "DrivingPlane"
Method | Class | Description | Return type |
---|---|---|---|
string |
File /Folder
|
Convert to string | string |
char |
File /Folder
|
Convert to char array | char |
cellstr |
File /Folder
|
Convert to cell of char arrays | cell |
Method | Class | Description | Return type |
---|---|---|---|
name |
File /Folder
|
File or folder name without directory |
File /Folder
|
parent |
File /Folder
|
Parent directory | Folder |
root |
File /Folder
|
First directory element of absolute paths | Folder |
stem |
File |
File name without extension | string |
extension |
File |
File extension | string |
parts |
File /Folder
|
Split path into list comprising root, folders and name | string |
strlength |
File /Folder
|
Number of characters in the path string | double |
absolute |
File /Folder
|
Absolute path assuming the current working directory as reference |
File /Folder
|
relative |
File /Folder
|
Path relative to reference directory |
File /Folder
|
is |
File /Folder
|
Whether properties match patterns | logical |
isAbsolute , isRelative
|
File /Folder
|
Whether path is absolute or relative | logical |
Method | Class | Description | Return type |
---|---|---|---|
/ , \ , append
|
Folder |
Join paths. Deduce if file or folder. |
File /Folder
|
appendFile |
Folder |
Join folder and file path. | File |
appendFolder |
Folder |
Join two folder paths. | Folder |
Method | Class | Description | Return type |
---|---|---|---|
setName |
File /Folder
|
Set file or folder name without directory |
File /Folder
|
setParent |
File /Folder
|
Set parent directory |
File /Folder
|
setRoot |
File /Folder
|
Set first directory element |
File /Folder
|
setStem |
File |
Set file name without extension | File |
setExtension |
File |
Set file extension | File |
addSuffix |
File /Folder
|
Add string to the end of the path |
File /Folder
|
addStemSuffix |
File |
Add string to the end of the file stem | File |
regexprep |
File /Folder
|
Wrapper for built-in regexprep
|
File /Folder
|
Method | Class | Description | Return type |
---|---|---|---|
== , eq
|
File /Folder
|
Whether path strings are equal | logical |
~= , ne
|
File /Folder
|
Whether path strings are unequal | logical |
Method | Class | Description | Return type |
---|---|---|---|
where |
File /Folder
|
Select paths where properties match patterns |
File /Folder
|
Method | Class | Description | Return type |
---|---|---|---|
exists |
File /Folder
|
Whether file or folder exists in filesystem | logical |
mustExist |
File /Folder
|
Raise error if file or folder does not exist | - |
dir |
File /Folder
|
Wrapper for built-in dir
|
struct |
modifiedDate |
File /Folder
|
Date and time of last modification | datetime |
createEmptyFile |
File |
Create an empty file | - |
fopen |
File |
Wrapper for built-in fopen
|
double ; char
|
open |
File |
Open file and return file ID and onCleanup object, which closes the file on destruction. Create parent folder if necessary. Raise error on failure. |
double ; onCleanup
|
readText |
File |
Read text file | string |
writeText |
File |
Write text file | - |
copy |
File /Folder
|
Copy to new path | - |
copyToFolder |
File /Folder
|
Copy into folder preserving the original name | - |
move |
File /Folder
|
Move to new path (rename) | - |
moveToFolder |
File /Folder
|
Move into folder preserving the original name | - |
delete |
File |
Delete file if it exists | - |
bytes |
File |
File size in bytes | - |
cd |
Folder |
Wrapper for built-in cd
|
Folder |
mkdir |
Folder |
Create folder if it does not already exist | - |
listFiles |
Folder |
List files in that folder | File |
listDeepFiles |
Folder |
List files in that folder and all its subdirectories | File |
listFolders |
Folder |
List directories in that folder | Folder |
listDeepFolders |
Folder |
List directories and subdirectories in that folder | Folder |
tempFile |
Folder |
Append random unique file name | File |
rmdir |
Folder |
Wrapper for built-in rmdir
|
- |
Method | Class | Description | Return type |
---|---|---|---|
isEmpty |
File /Folder
|
Check if array is empty | logical |
count |
File /Folder
|
Number of elements | double |
sort |
File /Folder
|
Sort by path string |
File /Folder ; double
|
unique_ |
File /Folder
|
Wrapper for built-in unique
|
File /Folder ; double ; double
|
deal |
File /Folder
|
Distribute array objects among output arguments |
File /Folder ; File /Folder ; ... |
Method | Description | Return type |
---|---|---|
Folder.current |
Current working directory; wrapper for built-in pwd
|
Folder |
Folder.home |
User home directory | Folder |
Folder.temp |
Temporary folder; wrapper for built-in tempdir
|
Folder |
File.temp |
Random unique file in temporary folder; wrapper for built-in tempname
|
Folder |
Folder.matlab |
Matlab install directory; wrapper for built-in matlabroot
|
Folder |
Folder.searchPath |
Folders on Matlab search path; wrapper for built-in path
|
Folder |
Folder.userPath |
Matlab user directory; wrapper for built-in userpath
|
Folder |
File.ofMatlabElement |
Path of Matlab file on the Matlab search path | File |
Folder.ofMatlabElement |
Folder of Matlab file on the Matlab search path | Folder |
File.ofCaller |
Path of Matlab file executing this method | File |
Folder.ofCaller |
Folder of Matlab file executing this method | Folder |
Method | Class | Description | Return type |
---|---|---|---|
disp |
File /Folder
|
Display in console | - |
help |
File /Folder
|
Open documentation web page | - |