import filelister as fs
You can create a Filelist object from a list
, set
, tuple
, Filelist
object, or path
to directory.
my_filelist = fs.Filelist(['../file_01.jpg', '../file_02.jpg'])
my_other_filelist = fs.Filelist('path/to/directory/')
You can also create a Filelist object by reading from a filelist saved on your system.
my_filelist = fs.read_filelist('path/to/filelist.txt')
Filelists support a number of conversions, including conversions to a native python list, to a relative filelist, and to an absolute filelist.
my_filelist.to_list()
my_filelist.to_abs()
my_filelist.to_rel()
These commands can also be chained:
my_filelist.to_abs().to_list()
Filelists support a cointains method, as well as the python in
operator.
my_filelist.contains('path/to/file')
'path/to/file' in my_filelist
A filelist can also be indexed and sliced like a normal python list. This will always return a native python list.
my_filelist[1] == 'path/to/file.txt'
my_filelist[:3] == ['path/to/file01.txt', 'path/to/file02.txt', 'path/to/file03.txt']
outfile
: specify a path to the location in which to write the filelist.
output_type
: specify the type of filelist to write. Options include 'abs'
, 'rel'
, and 'na'
(see below).
compressed
: accepts a boolean. Pass compressed=True
to write a compressed filelist.
my_filelist.save('filelists/my_filelist.txt', output_type='abs', compressed=True)
Note that when saving a relative filelist, the filepaths are converted to be relative to the location of the filelist.
A filelist can be stored using custom zlib compression by using
my_filelist.save(outfile='compressed_filelist.zz', compressed=True)
This filelist can then be read using
fs.read_filelist('compressed_filelist.zz', compressed=True)
Due to the nature of the compression, a compressed filelist should only be read by filelister.
Filelister supports three formats of filelists: Absolute, Relative, and "na"
abs
refers to an absolute filelist
['path/to/file_01.txt', 'path/to/file_02.txt', 'path/to/file_03.txt']
rel
refers to a relative filelists
['../file_01.txt', '../file_02.txt', '../file_03.txt']
na
refers to a filelist that is stored with no context, where filepaths are ignored and only filenames are stored
['file_01.txt', 'file_02.txt', 'file_03.txt']
pip install filelister
Coming soon