atomicshop 2.18.12__py3-none-any.whl → 2.18.13__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of atomicshop might be problematic. Click here for more details.
- atomicshop/__init__.py +1 -1
- atomicshop/filesystem.py +72 -0
- {atomicshop-2.18.12.dist-info → atomicshop-2.18.13.dist-info}/METADATA +1 -1
- {atomicshop-2.18.12.dist-info → atomicshop-2.18.13.dist-info}/RECORD +7 -7
- {atomicshop-2.18.12.dist-info → atomicshop-2.18.13.dist-info}/LICENSE.txt +0 -0
- {atomicshop-2.18.12.dist-info → atomicshop-2.18.13.dist-info}/WHEEL +0 -0
- {atomicshop-2.18.12.dist-info → atomicshop-2.18.13.dist-info}/top_level.txt +0 -0
atomicshop/__init__.py
CHANGED
atomicshop/filesystem.py
CHANGED
|
@@ -353,6 +353,78 @@ def rename_file(file_path: str, new_file_name: str) -> None:
|
|
|
353
353
|
os.rename(file_path, renamed_file_path)
|
|
354
354
|
|
|
355
355
|
|
|
356
|
+
def rename_file_with_special_characters(file_path: str) -> str:
|
|
357
|
+
"""
|
|
358
|
+
The function will rename the file to replace special characters from the file name with '_'.
|
|
359
|
+
If the file already exists, then the function will add a number to the end of the file name.
|
|
360
|
+
|
|
361
|
+
:param file_path: string, full path to file.
|
|
362
|
+
:return: string, full path to file with special characters renamed.
|
|
363
|
+
"""
|
|
364
|
+
|
|
365
|
+
# Get the file name without extension
|
|
366
|
+
file_stem: str = str(Path(file_path).stem)
|
|
367
|
+
file_extension: str = str(Path(file_path).suffix)
|
|
368
|
+
|
|
369
|
+
# Remove special characters from the file name
|
|
370
|
+
new_file_stem = strings.replace_strings_with_values_from_dict(
|
|
371
|
+
string_to_replace=file_stem, dictionary=FILE_NAME_REPLACEMENT_DICT)
|
|
372
|
+
|
|
373
|
+
# Rename the file
|
|
374
|
+
renamed_file_path = str(Path(file_path).parent) + os.sep + new_file_stem + file_extension
|
|
375
|
+
|
|
376
|
+
counter: int = 1
|
|
377
|
+
if os.path.isfile(renamed_file_path):
|
|
378
|
+
while True:
|
|
379
|
+
new_file_stem = f'{new_file_stem}_{counter}'
|
|
380
|
+
renamed_file_path = str(Path(file_path).parent) + os.sep + new_file_stem + file_extension
|
|
381
|
+
if not os.path.isfile(renamed_file_path):
|
|
382
|
+
break
|
|
383
|
+
counter += 1
|
|
384
|
+
|
|
385
|
+
os.rename(file_path, renamed_file_path)
|
|
386
|
+
|
|
387
|
+
return renamed_file_path
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
def rename_files_and_directories_with_special_characters(base_path: str) -> None:
|
|
391
|
+
"""
|
|
392
|
+
Recursively renames all files and directories in the given directory to rename special characters.
|
|
393
|
+
|
|
394
|
+
:param base_path: str, the base directory to start processing.
|
|
395
|
+
"""
|
|
396
|
+
|
|
397
|
+
def sanitize_name(name: str) -> str:
|
|
398
|
+
"""
|
|
399
|
+
Helper function to replace special characters in a string using a dictionary.
|
|
400
|
+
"""
|
|
401
|
+
for key, value in FILE_NAME_REPLACEMENT_DICT.items():
|
|
402
|
+
name = name.replace(key, value)
|
|
403
|
+
return name
|
|
404
|
+
|
|
405
|
+
# Walk through the directory tree in reverse to ensure we rename files before directories
|
|
406
|
+
for root, dirs, files in os.walk(base_path, topdown=False):
|
|
407
|
+
# Rename files in the current directory
|
|
408
|
+
for file_name in files:
|
|
409
|
+
old_path = Path(root) / file_name
|
|
410
|
+
sanitized_name = sanitize_name(file_name)
|
|
411
|
+
new_path = Path(root) / sanitized_name
|
|
412
|
+
|
|
413
|
+
if sanitized_name != file_name: # Rename only if the name changed
|
|
414
|
+
# print(f"Renaming file: {old_path} -> {new_path}")
|
|
415
|
+
os.rename(old_path, new_path)
|
|
416
|
+
|
|
417
|
+
# Rename directories in the current directory
|
|
418
|
+
for dir_name in dirs:
|
|
419
|
+
old_path = Path(root) / dir_name
|
|
420
|
+
sanitized_name = sanitize_name(dir_name)
|
|
421
|
+
new_path = Path(root) / sanitized_name
|
|
422
|
+
|
|
423
|
+
if sanitized_name != dir_name: # Rename only if the name changed
|
|
424
|
+
# print(f"Renaming directory: {old_path} -> {new_path}")
|
|
425
|
+
os.rename(old_path, new_path)
|
|
426
|
+
|
|
427
|
+
|
|
356
428
|
@contextmanager
|
|
357
429
|
def temporary_rename(file_path: str, temp_file_path) -> None:
|
|
358
430
|
# noinspection GrazieInspection
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
atomicshop/__init__.py,sha256=
|
|
1
|
+
atomicshop/__init__.py,sha256=5pTnN5bNMJA67RrDEqtb62Sy0aI4w2T53yo9d-LxiwE,124
|
|
2
2
|
atomicshop/_basics_temp.py,sha256=6cu2dd6r2dLrd1BRNcVDKTHlsHs_26Gpw8QS6v32lQ0,3699
|
|
3
3
|
atomicshop/_create_pdf_demo.py,sha256=Yi-PGZuMg0RKvQmLqVeLIZYadqEZwUm-4A9JxBl_vYA,3713
|
|
4
4
|
atomicshop/_patch_import.py,sha256=ENp55sKVJ0e6-4lBvZnpz9PQCt3Otbur7F6aXDlyje4,6334
|
|
@@ -14,7 +14,7 @@ atomicshop/dns.py,sha256=5Gimq_WY2arqg7BeGmR7P--fGfnH0Dsh8lrOt_H0jRY,6817
|
|
|
14
14
|
atomicshop/domains.py,sha256=Rxu6JhhMqFZRcoFs69IoEd1PtYca0lMCG6F1AomP7z4,3197
|
|
15
15
|
atomicshop/emails.py,sha256=I0KyODQpIMEsNRi9YWSOL8EUPBiWyon3HRdIuSj3AEU,1410
|
|
16
16
|
atomicshop/file_types.py,sha256=-0jzQMRlmU1AP9DARjk-HJm1tVE22E6ngP2mRblyEjY,763
|
|
17
|
-
atomicshop/filesystem.py,sha256=
|
|
17
|
+
atomicshop/filesystem.py,sha256=Tr5Z3LRwW_u7i8JmAHmkicqdEGEJF9Ldz47A9mc-9r8,61169
|
|
18
18
|
atomicshop/functions.py,sha256=pK8hoCE9z61PtWCxQJsda7YAphrLH1wxU5x-1QJP-sY,499
|
|
19
19
|
atomicshop/get_process_list.py,sha256=8cxb7gKe9sl4R6H2yMi8J6oe-RkonTvCdKjRFqi-Fs4,6075
|
|
20
20
|
atomicshop/get_process_name_cmd_dll.py,sha256=CtaSp3mgxxJKCCVW8BLx6BJNx4giCklU_T7USiCEwfc,5162
|
|
@@ -320,8 +320,8 @@ atomicshop/wrappers/socketw/statistics_csv.py,sha256=fgMzDXI0cybwUEqAxprRmY3lqbh
|
|
|
320
320
|
atomicshop/wrappers/winregw/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
321
321
|
atomicshop/wrappers/winregw/winreg_installed_software.py,sha256=on99OTT1_0g4KITAW5mSugUYgCAdVikhWjJ78a7JVIQ,1785
|
|
322
322
|
atomicshop/wrappers/winregw/winreg_network.py,sha256=AENV88H1qDidrcpyM9OwEZxX5svfi-Jb4N6FkS1xtqA,8851
|
|
323
|
-
atomicshop-2.18.
|
|
324
|
-
atomicshop-2.18.
|
|
325
|
-
atomicshop-2.18.
|
|
326
|
-
atomicshop-2.18.
|
|
327
|
-
atomicshop-2.18.
|
|
323
|
+
atomicshop-2.18.13.dist-info/LICENSE.txt,sha256=lLU7EYycfYcK2NR_1gfnhnRC8b8ccOTElACYplgZN88,1094
|
|
324
|
+
atomicshop-2.18.13.dist-info/METADATA,sha256=4SnW9QOBmr-koBAhc-X3XWJsGvfIDKajOMNHaSJRihk,10577
|
|
325
|
+
atomicshop-2.18.13.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
|
326
|
+
atomicshop-2.18.13.dist-info/top_level.txt,sha256=EgKJB-7xcrAPeqTRF2laD_Np2gNGYkJkd4OyXqpJphA,11
|
|
327
|
+
atomicshop-2.18.13.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|