move

FileSet.move(target=None, convert=None, copy=False, **kwargs)[source]

Move (or copy) files from this fileset to another location

Parameters
  • target – Either a FileSet object or the path (containing placeholders) where the files should be moved to.

  • convert – If true, the files will be read by the old fileset’s file handler and written to their new location by using the new file handler from target. Both file handlers must be compatible, i.e. the object that the old file handler’s read method returns must handable for the new file handler’s write method. You can also set this to a function that converts the return value of the read method into something else before it will be passed to the write method. Default is false, i.e. the file will be simply moved without converting.

  • copy – If true, then the original files will be copied instead of moved.

  • **kwargs – Additional keyword arguments that are allowed for find() such as start, end or files.

Returns

New FileSet object with the new files.

Examples:

## Copy all files between two dates to another location

old_fileset = FileSet(
    "old/path/{year}/{month}/{day}/{hour}{minute}{second}.nc",
)

# New fileset with other path
new_fileset = FileSet(
    "new/path/{year}/{doy}/{hour}{minute}{second}.nc",
)

old_fileset.move(
    new_fileset, start="2017-09-15", end="2017-09-23",
)
## Copy all files between two dates to another location and convert
## them to a different format

from typhon.files import CSV, NetCDF4

old_fileset = FileSet(
    "old/path/{year}/{month}/{day}/{hour}{minute}{second}.nc"
)
new_fileset = FileSet(
    "new/path/{year}/{doy}/{hour}{minute}{second}.csv"
)

# Note that this only works if both file handlers are compatible
new_fileset = old_fileset.move(
    new_fileset, convert=True, start="2017-09-15",
    end="2017-09-23",
)

# It is also possible to set the new path directly:
new_fileset = old_fileset.move(
    "new/path/{year}/{doy}/{hour}{minute}{second}.csv",
    convert=True, start="2017-09-15", end="2017-09-23",
)