GeoEco.DataManagement.Files.File.FindAndCopy

classmethod File.FindAndCopy(inputDirectory, outputDirectory, wildcard='*', searchTree=False, minSize=None, maxSize=None, minDateCreated=None, maxDateCreated=None, minDateModified=None, maxDateModified=None, destinationFilePythonExpression='os.path.join(destinationDirectory, sourceFile[len(directoryToSearch)+1:])', modulesToImport=['os.path'], skipExisting=False, overwriteExisting=False)

Finds and copies files in a directory.

Parameters:
  • inputDirectory (str) – Directory to search. Minimum length꞉ 1. Must exist.

  • outputDirectory (str) – Directory to receive copies of the files. Minimum length꞉ 1.

  • wildcard (str, optional) –

    UNIX-style “glob” wildcard expression specifying the pathnames to find.

    The glob syntax supports the following patterns:

    • ? - matches any single character

    • * - matches zero or more characters

    • [seq] - matches any single character in seq

    • [!seq] - matches any single character not in seq

    seq is one or more characters, such as abc. You may specify character ranges using a dash. For example, a-z0-9 specifies all of the characters in the English alphabet and the decimal digits 0 through 9.

    You may specify subdirectories in the glob expression. For example, the expression cruise*/sst* will find all paths beginning with sst that are contained in directories beginning with cruise.

    The operating system determines whether / or \ is used as the directory separator. On Windows, both will work. On Linux, / must be used.

    The operating system determines if matching is case sensitive. On Windows, matching is case-insensitive. On Linux, matching is case-sensitive. Minimum length꞉ 1.

  • searchTree (bool, optional) – If True, subdirectories will be searched.

  • minSize (int, optional) – Minimum size, in bytes, of files to find. If provided, only files that are this size or larger will be found. Minimum value꞉ 0.

  • maxSize (int, optional) – Maximum size, in bytes, of files to find. If provided, only files that are this size or smaller will be found. Minimum value꞉ 0.

  • minDateCreated (datetime, optional) – Minimum creation date, in the local time zone, of the files to find, as reported by the operating system. If provided, only files that were created on or after this date will be found. You may provide a date with or without a time. If you do not provide a time, it is assumed to be midnight.

  • maxDateCreated (datetime, optional) – Maximum creation date, in the local time zone, of the files to find, as reported by the operating system. If provided, only files that were created on or before this date will be found. You may provide a date with or without a time. If you do not provide a time, it is assumed to be midnight.

  • minDateModified (datetime, optional) – Minimum modification date, in the local time zone, of the files to find, as reported by the operating system. If provided, only files that were modified on or after this date will be found. You may provide a date with or without a time. If you do not provide a time, it is assumed to be midnight.

  • maxDateModified (datetime, optional) – Maximum modification date, in the local time zone, of the files to find, as reported by the operating system. If provided, only files that were modified on or before this date will be found. You may provide a date with or without a time. If you do not provide a time, it is assumed to be midnight.

  • destinationFilePythonExpression (str, optional) –

    Python expression used to calculate the absolute path of the destination file. The expression may be any Python statement appropriate for passing to the eval function and must return a Unicode string. The expression may reference the following variables:

    • directoryToSearch - the value provided for the directory to search parameter

    • destinationDirectory - the value provided for the destination directory parameter

    • sourceFile - the absolute path of the source file

    The default expression, os.path.join(destinationDirectory, sourceFile[len(directoryToSearch)+1:]), stores the file in the destination directory at the same relative location as it appears in the directory to search. The destination path is calculated by stripping the directory to search from the source path and replacing it with the destination directory.

    For more information on Python syntax, please see the Python documentation. Minimum length꞉ 1.

  • modulesToImport (list of str, optional) – Python modules to import prior to evaluating the expression. If you need to access Python functions or classes that are provided by a module rather than being built-in to the interpreter, list the module here. For example, to be able to use the datetime class in your expression, list the datetime module here. In your expression, you must refer to the class using its fully-qualified name, datetime.datetime.

  • skipExisting (bool, optional) – If True, copying will be skipped for destination files that already exist.

  • overwriteExisting (bool, optional) – If True and skipExisting is False, existing destination files will be overwritten.

Returns:

Directory to receive copies of the files.

Return type:

str