LocalFS

class paddle.distributed.fleet.utils. LocalFS [source]

A tool of local file system.

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> client = LocalFS()
>>> subdirs, files = client.ls_dir("./")
ls_dir ( fs_path )

ls_dir

List directorys and files under fs_path .

Parameters

fs_path (str) – The local file path.

Returns

Return a 2-tuple, the first is a list of all its subdirectories, and the second is a list of all its subfiles, e.g. ([subdirname1, subdirname1, …], [filename1, filename2, …]).

Return type

Tuple

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> client = LocalFS()
>>> subdirs, files = client.ls_dir("./")
mkdirs ( fs_path )

mkdirs

Create a local directory.

Parameters

fs_path (str) – The local directory path.

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> client = LocalFS()
>>> client.mkdirs("test_mkdirs")
>>> client.delete("test_mkdirs")
rename ( fs_src_path, fs_dst_path )

rename

Rename the file.

Parameters
  • fs_src_path (str) – The actual name of the file or directory

  • fs_dst_path (str) – The new name of the file or directory.

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> client = LocalFS()
>>> client.touch("test_rename_src")
>>> print(client.is_exist("test_rename_src"))
True
>>> client.rename("test_rename_src", "test_rename_dst")
>>> print(client.is_exist("test_rename_src"))
False
>>> print(client.is_exist("test_rename_dst"))
True
>>> client.delete("test_rename_dst")
delete ( fs_path )

delete

Delete the local file path, whether it’s a file or directory.

Parameters

fs_path (str) – The local file path.

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> client = LocalFS()
>>> client.mkdirs("test_localFS_mkdirs")
>>> client.delete("test_localFS_mkdirs")
is_file ( fs_path )

is_file

Whether the local file path is a file.

Parameters

fs_path (str) – The local file path.

Returns

Return true if the path exists and it’s a file, otherwise return false.

Return type

Bool

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> client = LocalFS()
>>> client.touch("test_is_file")
>>> print(client.is_file("test_is_file"))
True
>>> client.delete("test_is_file")
is_dir ( fs_path )

is_dir

Whether the local file path is a directory.

Parameters

fs_path (str) – The local file path.

Returns

Return true if the path exists and it’s a directory, otherwise return false.

Return type

Bool

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> client = LocalFS()
>>> client.mkdirs("test_is_dir")
>>> print(client.is_dir("test_is_dir"))
True
>>> client.delete("test_is_dir")
is_exist ( fs_path )

is_exist

Whether the local file path exists.

Parameters

fs_path (str) – The local file path.

Returns

Wheter it’s a file or directory, return true if the path exists, otherwise return false.

Return type

Bool

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> local_fs = LocalFS()
>>> ret = local_fs.is_exist("test_is_exist")
touch ( fs_path, exist_ok=True )

touch

Create a local file.

Parameters
  • fs_path (str) – The local file path.

  • exist_ok (bool) – When fs_path exists, if exist_ok is set false,

  • true. (program will throw an Exception. Default is) –

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> client = LocalFS()
>>> client.touch("test_touch")
>>> client.delete("test_touch")
mv ( src_path, dst_path, overwrite=False, test_exists=False )

mv

Move a local file or directory from src_path to dst_path .

Parameters
  • src_path (str) – Name of the file or directory, that’s needed to be moved.

  • dst_path (str) – Name of the file or directory to which to move to.

  • overwrite (bool) – Whether to re-write dst_path if that exists. Default is False.

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> client = LocalFS()
>>> client.touch("test_mv_src")
>>> client.mv("test_mv_src", "test_mv_dst")
>>> client.delete("test_mv_dst")
list_dirs ( fs_path )

list_dirs

Only list directorys under fs_path .

Parameters

fs_path (str) – The local file path.

Returns

A list of all its subdirectories, e.g. [subdirname1, subdirname1, …].

Return type

List

Examples

>>> 
>>> from paddle.distributed.fleet.utils import LocalFS

>>> client = LocalFS()
>>> subdirs = client.list_dirs("./")