Page 1 of 1
get list of directory items via script
Posted: 06 Dec 2022, 02:49
by woodslanding
Last time I checked this was not possible, but Olivier said he planned to implement it. Has this happened?
Suddenly a bigger issue, because I cannot supress the endless trace of 'file not found' messages in the beta FREE version--the page with the option to suppress is unavailable. But there are reasons I need to check for existing files, even otherwise.
In the past, I have cabled out to the file lister module and back in, but I'd love to get it inline in my scripts while I'm refactoring, it's much cleaner.
Re: get list of directory items via script
Posted: 06 Dec 2022, 11:43
by senso
will be implemented in the next release.
Code: Select all
const DirectorySeparator : Char = {$IFDEF MSWINDOWS} '\'; {$ELSE} '/'; {$ENDIF}
const LineEnding = #13#10;
function GetApplicationPath:string; //give the absolute path of the current Usine's folder
procedure FindFiles(const Directory: String; Extensions: String; Recursive: Boolean; Result: TStringList); // [Extensions] can be a comma-text
procedure FindDirectories(const Directory: String; Recursive: Boolean; Result: TStringList);
function WriteFileContents(const FileName: String; const Text: String; Append: Boolean): Boolean;
function ReadFileContents(const FileName: String): String;
function CreateDirectory(const Directory: String): Boolean;
function ForceDirectories(const Directory: String): Boolean;
function DeleteDirectory(const Directory: String; OnlyChildren: Boolean): Boolean;
function DeleteFile(const FileName: String): Boolean;
function RenameFile(const OldFileName, NewFileName: String): Boolean;
function CopyFile(const SourceFileName, DestFileName: String; Overwrite: Boolean = False): Boolean;
function FileExists(const FileName: String): Boolean;
function DirectoryExists(const Directory: String): Boolean;
function FileAge(const FileName: String): Int32; overload;
function FileAge(const FileName: String; out FileDateTime: TDateTime): Boolean; overload;
function ExtractFilePath(const FileName: String): String;
function ExtractFileDrive(const FileName: String): String;
function ExtractFileName(const FileName: String): String;
function ExtractFileExt(const FileName: String): String;
function ExtractFileDir(const FileName: String): String;
function ExpandFileName(const FileName: String): String;
function ExtractRelativePath(const BaseName, DestName: String): String;
function IncludeTrailingPathDelimiter(const Path: String) : String;
function ExcludeTrailingPathDelimiter(const Path: String): String;
function IncludeTrailingBackslash(const Path: String) : String;
function ExcludeTrailingBackslash(const Path: String): String;
function IncludeLeadingPathDelimiter(const Path : String) : String;
function ExcludeLeadingPathDelimiter(const Path: String): String;
// for compatibility
function SubFileExt(filename:String):string;
function PathDelim:string; // returns '/' on MACOS, '\' on windows
procedure CreateDir(dir:String);
Re: get list of directory items via script
Posted: 07 Dec 2022, 01:50
by woodslanding
Thanks, Senso, that's great!
Can someone explain the meaning of 'const' in these definitions? I've never encountered it in arguments to a method before this release.
EDIT: of course, as soon as I hit send, I think of a possibility... does it mean you can't change its value in the method body??
Re: get list of directory items via script
Posted: 07 Dec 2022, 07:43
by senso
Code: Select all
Can someone explain the meaning of 'const' in these definitions?
yes it means that you can't change it's value inside the procedure, so the procedure call is a little faster.