@@ -48,26 +48,28 @@ def unzip(path_to_zip_file, out_dir=None, verbose=False, raise_error=False, **kw
4848 >>> from pyhelpers.dirs import cd, delete_dir
4949 >>> zip_file_path = cd("tests\\ data", "zipped.zip")
5050 >>> unzip(path_to_zip_file=zip_file_path, verbose=True)
51- Extracting "tests\\ data\\ zipped.zip" to "tests\\ data\\ zipped\\ " ... Done.
52- >>> out_file_pathname = cd("tests\\ data\\ zipped", "zipped.txt")
51+ Extracting ".\\ tests\\ data\\ zipped.zip" to ".\\ tests\\ data\\ zipped\\ " ... Done.
52+ >>> output_dir_1 = cd("tests\\ data\\ zipped")
53+ >>> out_file_pathname = cd(output_dir_1, "zipped.txt")
5354 >>> with open(out_file_pathname) as f:
5455 ... print(f.read())
5556 test
56- >>> output_dir = cd("tests\\ data\\ zipped_alt")
57- >>> unzip(path_to_zip_file=zip_file_path, out_dir=output_dir , verbose=True)
58- Extracting "tests\\ data\\ zipped.zip" to "tests\\ data\\ zipped_alt\\ " ... Done.
59- >>> out_file_pathname = cd("tests \\ data \\ zipped_alt" , "zipped.txt")
57+ >>> output_dir_2 = cd("tests\\ data\\ zipped_alt")
58+ >>> unzip(path_to_zip_file=zip_file_path, out_dir=output_dir_2 , verbose=True)
59+ Extracting ". \\ tests\\ data\\ zipped.zip" to ". \\ tests\\ data\\ zipped_alt\\ " ... Done.
60+ >>> out_file_pathname = cd(output_dir_2 , "zipped.txt")
6061 >>> with open(out_file_pathname) as f:
6162 ... print(f.read())
6263 test
63- >>> # Delete the directories "tests\\ data\\ zipped\\ " and "tests\\ data\\ zipped_alt\\ "
64- >>> delete_dir([cd("tests \\ data \\ zipped"), output_dir ], verbose=True)
64+ >>> # Delete the directories ". \\ tests\\ data\\ zipped\\ " and ". \\ tests\\ data\\ zipped_alt\\ "
65+ >>> delete_dir([output_dir_1, output_dir_2 ], verbose=True)
6566 To delete the following directories:
66- "tests\\ data\\ zipped\\ " (Not empty)
67- "tests\\ data\\ zipped_alt\\ " (Not empty)
67+ ". \\ tests\\ data\\ zipped\\ " (Not empty)
68+ ". \\ tests\\ data\\ zipped_alt\\ " (Not empty)
6869 ? [No]|Yes: yes
69- Deleting "tests\\ data\\ zipped\\ " ... Done.
70- Deleting "tests\\ data\\ zipped_alt\\ " ... Done.
70+ Deleting ".\\ tests\\ data\\ zipped\\ " ... Done.
71+ Deleting ".\\ tests\\ data\\ zipped_alt\\ " ... Done.
72+
7173 """
7274
7375 if out_dir is None :
@@ -77,9 +79,9 @@ def unzip(path_to_zip_file, out_dir=None, verbose=False, raise_error=False, **kw
7779 os .makedirs (name = out_dir )
7880
7981 if verbose :
80- rel_path = os . path . relpath ( path = path_to_zip_file )
81- out_dir_ = os .path .relpath (path = out_dir ) + ( " \\ " if not out_dir . endswith ( " \\ " ) else "" )
82- print (" Extracting \" {} \" to \" {} \" " . format ( rel_path , out_dir_ ) , end = " ... " )
82+ rel_path , out_dir_ = map (
83+ lambda x : _add_slashes ( os .path .relpath (x )), [ path_to_zip_file , out_dir ] )
84+ print (f' Extracting { rel_path } to { out_dir_ } ' , end = " ... " )
8385
8486 try :
8587 with zipfile .ZipFile (file = path_to_zip_file ) as zf :
@@ -119,14 +121,15 @@ def seven_zip(path_to_zip_file, out_dir=None, mode='aoa', verbose=False, raise_e
119121 >>> from pyhelpers.dirs import cd, delete_dir
120122 >>> zip_file_pathname = cd("tests\\ data", "zipped.zip")
121123 >>> seven_zip(path_to_zip_file=zip_file_pathname, verbose=True)
122- 7-Zip 20.00 alpha (x64) : Copyright (c) 1999-2020 Igor Pavlov : 2020-02-06
124+
125+ 7-Zip 24.09 (x64) : Copyright (c) 1999-2024 Igor Pavlov : 2024-11-29
123126
124127 Scanning the drive for archives:
125128 1 file, 158 bytes (1 KiB)
126129
127- Extracting archive: \\ tests\\ data\\ zipped.zip
130+ Extracting archive: . \\ tests\\ data\\ zipped.zip
128131 --
129- Path = \\ tests\\ data\\ zipped.zip
132+ Path = . \\ tests\\ data\\ zipped.zip
130133 Type = zip
131134 Physical Size = 158
132135
@@ -136,28 +139,31 @@ def seven_zip(path_to_zip_file, out_dir=None, mode='aoa', verbose=False, raise_e
136139 Compressed: 158
137140
138141 Done.
139-
140- >>> out_file_pathname = cd("tests \\ data \\ zipped" , "zipped.txt")
142+ >>> output_dir_1 = cd("tests \\ data \\ zipped")
143+ >>> out_file_pathname = cd(output_dir_1 , "zipped.txt")
141144 >>> with open(out_file_pathname) as f:
142145 ... print(f.read())
143146 test
144- >>> output_dir = cd("tests\\ data\\ zipped_alt")
145- >>> seven_zip(path_to_zip_file=zip_file_pathname, out_dir=output_dir , verbose=False)
147+ >>> output_dir_2 = cd("tests\\ data\\ zipped_alt")
148+ >>> seven_zip(path_to_zip_file=zip_file_pathname, out_dir=output_dir_2 , verbose=False)
146149 >>> out_file_pathname = cd("tests\\ data\\ zipped_alt", "zipped.txt")
147150 >>> with open(out_file_pathname) as f:
148151 ... print(f.read())
149152 test
150153 >>> # Extract a .7z file
151154 >>> zip_file_path = cd("tests\\ data", "zipped.7z")
152- >>> seven_zip(path_to_zip_file=zip_file_path, out_dir=output_dir )
155+ >>> seven_zip(path_to_zip_file=zip_file_path, out_dir=output_dir_2 )
153156 >>> out_file_pathname = cd("tests\\ data\\ zipped", "zipped.txt")
154157 >>> with open(out_file_pathname) as f:
155158 ... print(f.read())
156159 test
157- >>> # Delete the directory: ".\\ tests\\ data\\ zipped_alt\\ "
158- >>> delete_dir(output_dir, verbose=True)
159- To delete the directory ".\\ tests\\ data\\ zipped_alt\\ " (Not empty)
160+ >>> # Delete the directories ".\\ tests\\ data\\ zipped\\ " and ".\\ tests\\ data\\ zipped_alt\\ "
161+ >>> delete_dir([output_dir_1, output_dir_2], verbose=True)
162+ To delete the following directories:
163+ ".\\ tests\\ data\\ zipped\\ " (Not empty)
164+ ".\\ tests\\ data\\ zipped_alt\\ " (Not empty)
160165 ? [No]|Yes: yes
166+ Deleting ".\\ tests\\ data\\ zipped\\ " ... Done.
161167 Deleting ".\\ tests\\ data\\ zipped_alt\\ " ... Done.
162168 """
163169
@@ -233,12 +239,12 @@ def markdown_to_rst(path_to_md, path_to_rst, reverse=False, engine=None, pandoc_
233239 >>> from pyhelpers.store import markdown_to_rst
234240 >>> from pyhelpers.dirs import cd
235241 >>> dat_dir = cd("tests\\ documents")
236- >>> path_to_md_file = cd(dat_dir, "readme .md")
237- >>> path_to_rst_file = cd(dat_dir, "readme .rst")
242+ >>> path_to_md_file = cd(dat_dir, "readme1 .md")
243+ >>> path_to_rst_file = cd(dat_dir, "readme1 .rst")
238244 >>> markdown_to_rst(path_to_md_file, path_to_rst_file, verbose=True)
239- Converting "tests\\ data \\ markdown .md" to "tests\\ data \\ markdown .rst" ... Done.
245+ Converting ". \\ tests\\ documents \\ readme .md" to ". \\ tests\\ documents \\ readme .rst" ... Done.
240246 >>> markdown_to_rst(path_to_md_file, path_to_rst_file, engine='pypandoc', verbose=True)
241- Updating "readme.rst" at ".\\ tests\\ documents\" ... Done.
247+ Updating "readme.rst" at ".\\ tests\\ documents\\ " ... Done.
242248 """
243249
244250 exe_name = "pandoc.exe"
@@ -260,7 +266,7 @@ def markdown_to_rst(path_to_md, path_to_rst, reverse=False, engine=None, pandoc_
260266 lambda x : pathlib .Path (_check_relative_pathname (x )), (abs_input_path , abs_output_path ))
261267
262268 if not os .path .exists (abs_output_path ):
263- msg = f'Converting " { rel_input_path } " to { _add_slashes (rel_output_path )} '
269+ msg = f'Converting { _add_slashes ( rel_input_path ) } to { _add_slashes (rel_output_path )} '
264270 else :
265271 msg = f'Updating "{ rel_output_path .name } " at { _add_slashes (rel_output_path .parent )} '
266272 print (msg , end = " ... " )
@@ -447,7 +453,7 @@ def xlsx_to_csv(path_to_xlsx, path_to_csv=None, engine=None, if_exists='replace'
447453 >>> import os
448454 >>> path_to_test_xlsx = cd("tests\\ data", "dat.xlsx")
449455 >>> path_to_temp_csv = xlsx_to_csv(path_to_test_xlsx, verbose=True)
450- Converting "tests\\ data\\ dat.xlsx" to a (temporary) CSV file ... Done.
456+ Converting ". \\ tests\\ data\\ dat.xlsx" to a (temporary) CSV file ... Done.
451457 >>> os.path.isfile(path_to_temp_csv)
452458 True
453459 >>> data = load_csv(path_to_temp_csv, index=0)
@@ -460,7 +466,7 @@ def xlsx_to_csv(path_to_xlsx, path_to_csv=None, engine=None, if_exists='replace'
460466 Leeds -1.5437941 53.7974185
461467 >>> # Set `engine='xlsx2csv'`
462468 >>> temp_csv_buffer = xlsx_to_csv(path_to_test_xlsx, engine='xlsx2csv', verbose=True)
463- Converting "tests\\ data\\ dat.xlsx" to a (temporary) CSV file ... Done.
469+ Converting ". \\ tests\\ data\\ dat.xlsx" to a (temporary) CSV file ... Done.
464470 >>> # import pandas as pd; data_ = pandas.read_csv(io_buffer, index_col=0)
465471 >>> data_ = load_csv(temp_csv_buffer, index=0)
466472 >>> data_
@@ -478,7 +484,7 @@ def xlsx_to_csv(path_to_xlsx, path_to_csv=None, engine=None, if_exists='replace'
478484
479485 if verbose :
480486 rel_path = _check_relative_pathname (path_to_xlsx )
481- print (f" Converting \" { rel_path } \" to a (temporary) CSV file" , end = " ... " )
487+ print (f' Converting { _add_slashes ( rel_path ) } to a (temporary) CSV file' , end = " ... " )
482488
483489 if engine is None :
484490 vbscript_ , csv_pathname = _xlsx_to_csv_prep (
0 commit comments