sdtu.f
Purpose
File utilities.
find
Find files matching a name
sdtu.f.find('@sdt/help/sdt.pdf')
li=sdtu.f.find('@sdt/fe*.m')
cffile
sdtu.f.cffile canonical full file path resolution
Syntax: sdth.fileutil('cffile',fname)
This command gets back the canonical path (mainly resolves symlinks with a unique hard link, relative path features /../, ...).
abs2rel
sdtu.f.abs2rel relative path resolution
Syntax: [fname,wd]=sdth.fileutil('abs2rel',FileName,root)
This command gets back relative path fname and root if root is an effective root of FileName, else gets back FileName and an empty wd.
rel2abs
sdtu.f.rel2abs absolute path resolution
Syntax: FileName=sdth.fileutil('rel2abs',fname,root)
This command gets back fname if it is already an absolute path, else gets back the concatenation of root and fname.
firstdir
wd=sdth.fileutil('firstdir',wd1,wd2) gets back the first found directory in the provided list, the following command options are available:
- cd: move the current directory to the found folder.
- base: assign in base the found folder in variable wd.
fileutil
sdtu.f.fileutil file handling utilities handles folder search, canonical path resolution, switches between full and relative path, file locking...
-
fsafe: series of safe file handling commands, checking file existance, HDF5 mode interactions, and locks with fjlock to avoid corruption and potential errors. It also aims at porting usefull linux file commands on Windows platforms.
-
save: sdth.fileutil('fsafe','save',fname,'var',....): overloads save function, taking the same arguments after the save token. Lock checks, HDF5 robustness, -append token handling with file preexistence.
- savekeep: sdth.fileutil('fsafe','savekeep',fname,'var',....): same as save command but saves preexistent file with a numeric ending root.
- load: sdth.fileutil('fsafe','load',fname,'var',....): overloads load function, taking the same arguments after the load token. Lock checks, added SDT handles robustness for path changes.
- delete: sdth.fileutil('fsafe','delete',fname): overloads delete function. Lock checks, fail safe.
- move: sdth.fileutil('fsafe','move',fnameOld,fnameNew): alternative movefile command. Lock checks, performs an atomic move using java.nio if available.
- movenoe: sdth.fileutil('fsafe','movenoe',fnameOld,fnameNew): same as move but fail safe.
- printw: sdth.fileutil('fsafe','printw',fname,fmt,strings): integrared print to file. Opens fname in w mode and calls fprintf with fmt and strings. Lock checks.
- tail: st=sdth.fileutil('fsafe','tail',fname,nc): outputs in st the last nc characters of file fname. Efficient alternative to linux command tail on all OSes. Lock checks. Usefull for log file monitoring.
- whos: li=sdt.fileutil('fsafe','whos',fname): overloads whos -file command. Lock and existence checks, HDF5 robustness. If no output is required, quicker and robust display if provided for HDF5 files.
- whosl: li=sdt.fileutil('fsafe','whosl',fname): same as whos but only provides the list of saved variables, very quick for HDF5 files when no more information is required.
- prf: handling of a preferences file in the .prf format. Used to store history data associated to applications. By default, fullfile(sdtdef('tempdir'),'sdt.prf' is used, sdt can be replaced by another rootVal in the command. Get/Set comands are defined as follows:
-
prfSet: data=sdth.fileutil('prfget rootVal',name,fmt) reads preference name of format fmt in fullfile(sdtdef('tempdir'),'rootVal.prf'). Supported formats are S for strings and G for real values.
- prfSet: sdth.fileutil('prfset rootVal',name,fmt,data) sets preference name of format fmt to data in fullfile(sdtdef('tempdir'),'rootVal.prf'). Supported formats are S for strings and G for real values.
- bashwd: replaces drive names and backslashes for cygwin calls. e.g. O:
is replaced by /mnt/o/.cygpath=sdth.fileutil('bashwd',winpath).
- fnlength: truncates a file name of over 200 characters. Replaces all character set over 200 by ___. ftrunc=sdth.fileutil('fnlength',fname).
-
prf : handling of a preferences file in the .prf format. Used to store history data associated to applications. By default, fullfile(sdtdef('tempdir'),'sdt.prf' is used, sdt can be replaced by another rootVal in ]: #
[the command.]: #
-
prfset : data=sdth.fileutil('prfget rootVal',name,fmt): reads preference name of format fmt in fullfile(sdtdef('tempdir'),'rootVal.prf'. Supported formats are S for strings and G for real values.
- prfset : sdth.fileutil('prfset rootVal',name,fmt,data): sets preference name of format fmt to data in fullfile(sdtdef('tempdir'),'rootVal.prf'. Supported formats are S for strings and G for real values.
©1991-2025 by SDTools