Path

version 1.8.2 (27.9 KB) by Martin Koch
Write short and readable code to solve your filesystem path problems.

56 Downloads

Updated 26 May 2022

From GitHub

View License on GitHub

Path

Classes for handling filesystem paths in MATLAB.

The File and Folder classes allow you to solve your path-related problems using short and readable code.

View Path on File Exchange

Features

  • Get and set path name, parent, root, stem and extension
  • Filter paths by extension, name, etc. using wildcards
  • List files recursively
  • Handle lists of paths
  • Clean and resolve paths
  • Build absolute and relative paths
  • Automatically create folder when writing files and throw error on failure
  • Get folder of currently executing MATLAB file

Examples

Path properties

>> file = File("C:\data\model.dat")
   File("C:\data\model.dat")
>> file.parent
   Folder("C:\data")
>> file.stem
   "model"
>> file.extension
   ".dat"

Arrays of paths

>> personalFolders = Folder("astronauts") / ["Andrew", "Trudy", "Sniffels"]
    Folder("astronauts\Andrew")
    Folder("astronauts\Trudy")
    Folder("astronauts\Sniffels")
>> personalFolders.append("DONT_PANIC.txt").createEmptyFile;

Filtering and chaining

>> files = Folder("Sketchy Folder").listDeepFiles
    File("Sketchy Folder\DeleteStuffVirus.exe")
    File("Sketchy Folder\System32\nastyWorm.dll")
    File("Sketchy Folder\dark_corner\half_a_sandwich.dat")
    File("Sketchy Folder\WormholeResearch.pdf")
>> files.where("Stem", ["*Virus*", "*Worm*"], "ExtensionNot", ".pdf").copyToFolder("D:\Quarantine");

Get path of executing file

>> scriptFile = File.ofCaller
    File("/MATLAB Drive/YesIMadeAnExtraScriptToDemonstrateThis.m")
>> scriptFile.parent.cd;

Installation

Download this repository and add it to your MATLAB search path. Requires R2019b or newer.

Documentation

Find the documentation in the wiki.

Cite As

Martin Koch (2022). Path (https://github.com/MartinKoch123/Path/releases/tag/v1.8.2), GitHub. Retrieved .

MATLAB Release Compatibility
Created with R2020b
Compatible with R2019b and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
To view or report issues in this GitHub add-on, visit the GitHub Repository.
To view or report issues in this GitHub add-on, visit the GitHub Repository.