| Avidemux 2.6 Scripting Reference

- Main Page
- Modules
- Classes
- Examples

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Functions Enumerations Enumerator Properties Groups Pages
Public Types | Public Member Functions | Properties | List of all members
Directory Class Reference

The Directory class provides access to directory structures and their contents. More...

## Public Types
enum | Filter { Directories = 0x001, Files = 0x002, Drives = 0x004, NoSymLinks = 0x008, AllEntries = Directories | Files | Drives, Readable = 0x010, Writable = 0x020, Executable = 0x040, Modified = 0x080, Hidden = 0x100, System = 0x200, AllDirectories = 0x400, CaseSensitive = 0x800, NoDotAndDotDot = 0x1000, NoFilter = -1 }
| Describes the filtering options available to Directory; e.g. for entryList() and entryInfoList(). More...
enum | Sort { Name = 0x00, Time = 0x01, Size = 0x02, Type = 0x80, Unsorted = 0x03, DirectoriesFirst = 0x04, Reversed = 0x08, IgnoreCase = 0x10, DirectoriesLast = 0x20, LocaleAware = 0x40, NoSort = -1 }
| Describes the sort options available to Directory, e.g. for entryList() and entryInfoList(). More...

## Public Member Functions
String | absoluteFilePath (String fileName)
| Returns the absolute path name of a file in the directory.
Boolean | changeDirectory (String dirName)
| Changes the Directory object's directory to dirName.
Boolean | changeDirectoryUp ()
| Changes directory by moving one directory up from the Directory object's current directory.
String | cleanPath (String path)
| Removes all multiple directory separators "/" and resolves any "." or ".." found in the path.
| Directory (String path="")
| Constructs a Directory object pointing to the given directory path. If path is empty the program's working directory, ("."), is used.
| Directory (String path, String nameFilter, Sort sort=Sort(Name|IgnoreCase), Filter filter=AllEntries)
| Constructs a Directory object with specified path, that filters its entries by name using nameFilter and by attributes using filter. It also sorts the names using sort.
Array | entryInfoList (Filter filters=NoFilter, Sort sort=NoSort)
| Returns a list of FileInformation objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with the nameFilters and filter properties, and sorted according to the flags set with the sorting property.
Array | entryInfoList (Array nameFilters, Filter filters=NoFilter, Sort sort=NoSort)
| Returns a list of FileInformation objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with the nameFilters and filter properties, and sorted according to the flags set with the sorting property.
Array | entryList (Filter filters=NoFilter, Sort sort=NoSort)
| Returns a list of the names of all the files and directories in the directory.
Array | entryList (Array nameFilters, Filter filters=NoFilter, Sort sort=NoSort)
| Returns a list of the names of all the files and directories in the directory.
Boolean | exists (String name)
| Returns true if the file called name exists; otherwise returns false.
String | filePath (String fileName)
| Returns the path name of a file in the directory.
String | fromNativeSeparators (String pathName)
| Returns pathName using '/' as file separator.
Boolean | makeAbsolute ()
| Converts the directory path to an absolute path.
Boolean | makeDirectory (String dirName)
| Creates a sub-directory called dirName.
Boolean | makePath (String dirPath)
| Creates the directory path dirPath.
Boolean | match (Array filters, String fileName)
| Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; otherwise returns false.
Boolean | match (String filter, String fileName)
| Returns true if the fileName matches the wildcard (glob) pattern filter; otherwise returns false.
void | refresh ()
| Refreshes the directory information.
String | relativeFilePath (String fileName)
| Returns the path to fileName relative to the directory.
Boolean | remove (String fileName)
| Removes the file, fileName.
Boolean | removeDirectory (String dirName)
| Removes the directory specified by dirName.
Boolean | removePath (String dirPath)
| Removes the directory path dirPath.
Boolean | rename (String oldName, String newName)
| Renames a file or directory from oldName to newName.
String | toNativeSeparators (String pathName)
| Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.

## Properties
String | absolutePath
| Returns the absolute path (a path that starts with "/" or with a drive specification), which may contain symbolic links, but never contains redundant ".", ".." or multiple separators.
String | canonicalPath
| Returns the canonical path, i.e. a path without symbolic links or redundant "." or ".." elements.
Number | count
| Returns the total number of directories and files in the directory.
String | currentPath
| Gets or sets the current path.
String | directoryName
| Returns the name of the directory.
Array | drives
| Returns a list of the root directories on this system.
Boolean | exists
| Returns true if the directory exists; otherwise returns false.
Filter | filter
| Gets or sets the filter used by entryList() and entryInfoList().
String | homePath
| Returns the absolute path of the user's home directory.
Boolean | isAbsolute
| Returns true if the directory's path is absolute; otherwise returns false.
Boolean | isReadable
| Returns true if the directory is readable and we can open files by name; otherwise returns false.
Boolean | isRelative
| Returns true if the directory path is relative; otherwise returns false.
Boolean | isRoot
| Returns true if the directory is the root directory; otherwise returns false.
Array | nameFilters
| Gets or sets the name filters used by entryList() and entryInfoList().
String | path
| Gets or sets the path of the Directory object.
String | rootPath
| Returns the absolute path of the root directory.
String | separator
| Returns the native directory separator: "/" under Unix (including Mac OS X) and "\" under Windows.
Sort | sorting
| Gets or sets the sort order used by entryList() and entryInfoList().
String | tempPath
| Returns the absolute path of the system's temporary directory.

## Detailed Description

The Directory class provides access to directory structures and their contents.

A Directory object is used to manipulate path names, access information regarding paths and files, and manipulate the underlying file system.

The Directory class uses "/" as a universal directory separator in the same way that "/" is used as a path separator in URLs. If you always use "/" as a directory separator, the Directory class will translate your paths to conform to the underlying operating system.

A Directory object can point to a file using either a relative or an absolute path. Absolute paths begin with the directory separator (optionally preceded by a drive specification under Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current directory.

Examples:
  TranscodeDirectory.admjs.

## Member Enumeration Documentation

enum Filter

Describes the filtering options available to Directory; e.g. for entryList() and entryInfoList().

The filter value is specified by combining values from the following list using the bitwise OR operator:

Enumerator:

  Directories | List directories that match the filters.
  Files | List files.
  Drives | List disk drives (ignored under Unix).
  NoSymLinks | Do not list symbolic links (ignored by operating systems that don't support symbolic links).
  AllEntries | List directories, files, drives and symlinks (this does not list broken symlinks unless you specify System).
  Readable | List files for which the application has read access. The Readable value needs to be combined with Directories or Files.
  Writable | List files for which the application has write access. The Writable value needs to be combined with Directories or Files.
  Executable | List files for which the application has execute access. The Executable value needs to be combined with Directories or Files.
  Modified | Only list files that have been modified (ignored under Unix).
  Hidden | List hidden files (on Unix, files starting with a ".").
  System | List system files (on Unix, FIFOs, sockets and device files).
  AllDirectories | List all directories; i.e. don't apply the filters to directory names.
  CaseSensitive | The filter should be case sensitive.
  NoDotAndDotDot | Do not list the special entries "." and "..".
  NoFilter | List everything.

Examples:
  TranscodeDirectory.admjs.

enum Sort

Describes the sort options available to Directory, e.g. for entryList() and entryInfoList().

The sort value is specified by combining values from the following list using the bitwise OR operator. You can only specify one of the first four. If you specify both DirectoriesFirst and Reversed, directories are still put first, but in reverse order; the files will be listed after the directories, again in reverse order.

Enumerator:

  Name | Sort by name.
  Time | Sort by time (modification time).
  Size | Sort by file size.
  Type | Sort by file type (extension).
  Unsorted | Do not sort.
  DirectoriesFirst | Put the directories first, then the files.
  Reversed | Reverse the sort order.
  IgnoreCase | Sort case-insensitively.
  DirectoriesLast | Put the files first, then the directories.
  LocaleAware | Sort items appropriately using the current locale settings.
  NoSort | No sorting.

Examples:
  TranscodeDirectory.admjs.

## Constructor & Destructor Documentation

Directory | ( | String | path,
|  | String | nameFilter,
|  | Sort | sort = `Sort(Name|IgnoreCase)`,
|  | Filter | filter = `AllEntries`
| ) |  |

Constructs a Directory object with specified path, that filters its entries by name using nameFilter and by attributes using filter. It also sorts the names using sort.

The default nameFilter is an empty string, which excludes nothing; the default filters is AllEntries, which also means exclude nothing. The default sort is Name | IgnoreCase, i.e. sort by name case-insensitively.

If path is an empty string, Directory uses "." (the current directory). If nameFilter is an empty string, Directory uses the name filter "*" (all files).

Note that path need not exist.

## Member Function Documentation

String absoluteFilePath | ( | String | fileName | ) |

Returns the absolute path name of a file in the directory.

Does not check if the file actually exists in the directory; but see Directory.exists. Redundant multiple separators or "." and ".." directories in fileName are not removed (see cleanPath()).

Boolean changeDirectory | ( | String | dirName | ) |

Changes the Directory object's directory to dirName.

Note that the logical cd() operation is not performed if the new directory does not exist. Calling cd("..") is equivalent to calling cdUp().

Returns
  Returns true if the new directory exists and is readable; otherwise returns false.

Boolean changeDirectoryUp | ( |  | ) |

Changes directory by moving one directory up from the Directory object's current directory.

Note that the logical changeDirectoryUp() operation is not performed if the new directory does not exist.

Returns
  Returns true if the new directory exists and is readable; otherwise returns false.

String cleanPath | ( | String | path | ) |

Removes all multiple directory separators "/" and resolves any "." or ".." found in the path.

Symbolic links are kept. This function does not return the canonical path, but rather the simplest version of the input. For example, "./local" becomes "local", "local/../bin" becomes "bin" and "/local/usr/../bin" becomes "/local/bin".

Array entryInfoList | ( | Filter | filters = `NoFilter`,
|  | Sort | sort = `NoSort`
| ) |  |

Returns a list of FileInformation objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with the nameFilters and filter properties, and sorted according to the flags set with the sorting property.

The name filter, file attribute filter, and sorting specification can be overridden using the nameFilters, filters, and sort arguments.

Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.

Examples:
  TranscodeDirectory.admjs.

Array entryInfoList | ( | Array | nameFilters,
|  | Filter | filters = `NoFilter`,
|  | Sort | sort = `NoSort`
| ) |  |

Returns a list of FileInformation objects for all the files and directories in the directory, ordered according to the name and attribute filters previously set with the nameFilters and filter properties, and sorted according to the flags set with the sorting property.

The attribute filter and sorting specifications can be overridden using the filters and sort arguments.

Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.

Array entryList | ( | Filter | filters = `NoFilter`,
|  | Sort | sort = `NoSort`
| ) |  |

Returns a list of the names of all the files and directories in the directory.

The list is ordered according to the name and attribute filters previously set with the nameFilters and filter properties. The list is also sorted according to the flags set with the sorting property.

The attribute filter and sorting specifications can be overridden using the filters and sort arguments.

Note: To list symlinks that point to non existing files, System must be passed to the filter.

Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.

Array entryList | ( | Array | nameFilters,
|  | Filter | filters = `NoFilter`,
|  | Sort | sort = `NoSort`
| ) |  |

Returns a list of the names of all the files and directories in the directory.

The list is ordered according to the name and attribute filters previously set with the nameFilters and filter properties. The list is also sorted according to the flags set with the sorting property.

The name filter, file attribute filter and sorting specification can be overridden using the nameFilters, filters, and sort arguments.

Returns an empty list if the directory is unreadable, does not exist, or if nothing matches the specification.

Boolean exists | ( | String | name | ) |

Returns true if the file called name exists; otherwise returns false.

Unless name contains an absolute file path, the file name is assumed to be relative to the current directory.

String filePath | ( | String | fileName | ) |

Returns the path name of a file in the directory.

Does not check if the file actually exists in the directory; but see Directory.exists. If the Directory object is relative, the returned path name will also be relative. Redundant multiple separators or "." and ".." directories in fileName are not removed (see cleanPath()).

String fromNativeSeparators | ( | String | pathName | ) |

Returns pathName using '/' as file separator.

On Windows, for instance, fromNativeSeparators("c:\\winnt\\system32") returns "c:/winnt/system32". The returned string may be the same as the argument on some operating systems, for example on Unix.

Boolean makeAbsolute | ( |  | ) |

Converts the directory path to an absolute path.

If it is already absolute nothing happens.

Returns
  Returns true if the conversion succeeded; otherwise returns false.

Boolean makeDirectory | ( | String | dirName | ) |

Creates a sub-directory called dirName.

Returns
  Returns true on success; otherwise returns false.

Boolean makePath | ( | String | dirPath | ) |

Creates the directory path dirPath.

The function will create all parent directories necessary to create the directory.

Returns
  Returns true if successful; otherwise returns false.

Boolean match | ( | Array | filters,
|  | String | fileName
| ) |  |

Returns true if the fileName matches any of the wildcard (glob) patterns in the list of filters; otherwise returns false.

The matching is case insensitive.

Boolean match | ( | String | filter,
|  | String | fileName
| ) |  |

Returns true if the fileName matches the wildcard (glob) pattern filter; otherwise returns false.

The filter may contain multiple patterns separated by spaces or semicolons. The matching is case insensitive.

Boolean remove | ( | String | fileName | ) |

Removes the file, fileName.

Returns
  Returns true if the file is removed successfully; otherwise returns false.

Boolean removeDirectory | ( | String | dirName | ) |

Removes the directory specified by dirName.

The directory must be empty for removeDirectory() to succeed.

Returns
  Returns true if successful; otherwise returns false.

Boolean removePath | ( | String | dirPath | ) |

Removes the directory path dirPath.

The function will remove all parent directories in dirPath, provided that they are empty. This is the opposite of makePath(dirPath).

Returns
  Returns true if successful; otherwise returns false.

Boolean rename | ( | String | oldName,
|  | String | newName
| ) |  |

Renames a file or directory from oldName to newName.

On most file systems, rename() fails only if oldName does not exist, if newName and oldName are not on the same partition or if a file with the new name already exists. However, there are also other reasons why rename() can fail. For example, on at least one file system rename() fails if newName points to an open file.

Returns
  Returns true if successful; otherwise returns false.

String toNativeSeparators | ( | String | pathName | ) |

Returns pathName with the '/' separators converted to separators that are appropriate for the underlying operating system.

On Windows, toNativeSeparators("c:/winnt/system32") returns "c:\winnt\system32". The returned string may be the same as the argument on some operating systems, for example on Unix.

## Property Documentation

String canonicalPath
| read

Returns the canonical path, i.e. a path without symbolic links or redundant "." or ".." elements.

On systems that do not have symbolic links this function will always return the same string that absolutePath returns. If the canonical path does not exist (normally due to dangling symbolic links) canonicalPath returns an empty string.

Number count
| read

Returns the total number of directories and files in the directory.

Equivalent to entryList().length.

String directoryName
| read

Returns the name of the directory.

A directory name isn't the same as the path, e.g. a directory with the name "mail", might have the path "/var/spool/mail". If the directory has no name (e.g. it is the root directory) an empty string is returned.

No check is made to ensure that a directory with this name actually exists; but see Directory.exists.

See Also
  exists

Array drives
| read

Returns a list of the root directories on this system.

On Windows this returns a list of FileInformation objects containing "C:/", "D:/", etc. On other operating systems, it returns a list containing just one root directory (i.e. "/").

Boolean exists
| read

Returns true if the directory exists; otherwise returns false.

If a file with the same name is found this function will return false.

Filter filter
| read write

Gets or sets the filter used by entryList() and entryInfoList().

The filter is used to specify the kind of files that should be returned by entryList() and entryInfoList().

String homePath
| read

Returns the absolute path of the user's home directory.

Under Windows this function will return the directory of the current user's profile. Typically, this is: C:/Documents and Settings/Username

Use the toNativeSeparators() function to convert the separators to the ones that are appropriate for the underlying operating system.

If the directory of the current user's profile does not exist or cannot be retrieved, the following alternatives will be checked (in the given order) until an existing and available path is found:

- The path specified by the USERPROFILE environment variable.
- The path formed by concatenating the HOMEDRIVE and HOMEPATH environment variables.
- The path specified by the HOME environment variable.
- The path returned by the rootPath property (which uses the SystemDrive environment variable).
- The C:/ directory.

Under non-Windows operating systems the HOME environment variable is used if it exists, otherwise the path returned by the rootPath() function is used.

Boolean isReadable
| read

Returns true if the directory is readable and we can open files by name; otherwise returns false.

Warning: A false value from this function isn't a guarantee that files in the directory are not accessible.

Boolean isRoot
| read

Returns true if the directory is the root directory; otherwise returns false.

Note: If the directory is a symbolic link to the root directory this function returns false. If you want to test for this use canonicalPath.

Array nameFilters
| read write

Gets or sets the name filters used by entryList() and entryInfoList().

Each name filter is a wildcard (globbing) filter that understands * and ? wildcards.

String path
| read write

Gets or sets the path of the Directory object.

The path is cleaned of redundant ".", ".." and of multiple separators. No check is made to see whether a directory with this path actually exists; but you can check for yourself using exists().

The path can be either absolute or relative. Absolute paths begin with the directory separator "/" (optionally preceded by a drive specification under Windows). Relative file names begin with a directory name or a file name and specify a path relative to the current directory. An example of an absolute path is the string "/tmp/quartz", a relative path might look like "src/fatlib".

String rootPath
| read

Returns the absolute path of the root directory.

For Unix operating systems this returns "/". For Windows file systems this normally returns "c:/".

String separator
| read

Returns the native directory separator: "/" under Unix (including Mac OS X) and "\" under Windows.

You do not need to use this function to build file paths. If you always use "/", the Directory class will translate your paths to conform to the underlying operating system. If you want to display paths to the user using their operating system's separator use toNativeSeparators()

String tempPath
| read

Returns the absolute path of the system's temporary directory.

On Unix/Linux systems this is usually /tmp; on Windows this is usually the path in the TEMP or TMP environment variable. Whether a directory separator is added to the end or not, depends on the operating system.