dirops
Module¶
dirops
module provides a DirOps
class
which retrieves basic information, performs operations on path.
Register module¶
>>> import farabio.data.imgops.DirOps as DirOps
>>> dir_path = './images/'
-
class
farabio.data.dirops.
DirOps
(path)[source]¶ Creates instance of DirOps class
- Attributes
- pathstr
path of interest
- dirslist of str
existing folders at path
- fileslist of str
existing filenames at path
- ndirsint
number of only folders at path
- nfilesint
number of files at cwd path, except folders
- dirsizestr
total occupied memory
- titemsint
total items including subdirectories
Methods
dirinfo(self)
Prints basic information in a neat format
split_traintest(self, ratio=0.8, shuffle=True)
Splits list of files into train and test, shuffles by default
lsmedia(self)
Returns media files from path
-
dirinfo
()[source]¶ Prints basic information in a neat format
Examples
>>> DirOps(dir_path).dirinfo()
-
split_traintest
(ratio=0.8, shuffle=True)[source]¶ Splits list of files in path into train and test
- Parameters
- ratiofloat
ratio to split into train and test
- shufflebool
flag to perform shuffle before split
- Returns
- train, testtuple of lists
Examples
>>> (train_list, test_list) = DirOps(dir_path).split_traintest(ratio=0.7)
-
lsmedia
()[source]¶ Returns media files from path
- Returns
- (img_fns, vid_fns, aud_fns)tuple of lists
img_fns : list of image files vid_fns : list of video files aud_fns : list of audio files
Examples
>>> DirOps(dir_path).lsmedia()
-
del_files
(reflist, match=True)[source]¶ Deletes files in current folder that matches / not matches with list
- Parameters
- reflistlist
list of items in folder
- matchbool
deletes files which match, if True
Examples
>>> sample_list = ['1.png', '3.png', '4.png'] >>> DirOps(dir_path).del_files(sample_list, match=False)