Work with files
Project description
File worker
User Guide
- Copy folder, change each file extension and paste folder
import shutil
import fileworker as fw
SOURCE_FOLDER_PATH = "data/test"
TARGET_FOLDER_PATH = "data/test_csv"
FILE_FORMAT = ".csv"
# Class for managing file paths
path_manager = fw.PathManager()
# Get a list of source paths
source_paths = path_manager.get_source_paths(SOURCE_FOLDER_PATH)
print("Source paths:", source_paths)
print("Number of source paths:", len(source_paths))
# Get a list of target paths with the ".csv" extension
target_paths = path_manager.get_target_paths(TARGET_FOLDER_PATH, FILE_FORMAT)
print("Target paths:", target_paths)
print("Number of target paths:", len(target_paths))
# Get a list of missing folder paths
target_missing_folder_paths = path_manager.get_target_folder_paths(skip_existing=True)
print("Target missing folder paths:", target_missing_folder_paths )
# Create missing folders
path_manager.create_missing_folders()
# Get a list of pairs of source and target files, skipping existing ones
path_pairs = path_manager.get_file_pairs(skip_existing=True)
print("List of source and target file pairs:", path_pairs)
for source_path, target_path in path_pairs:
print("Copying:", source_path, "->", target_path)
try:
shutil.copy(source_path, target_path)
except shutil.SameFileError:
print("Source and destination represents the same file.")
except PermissionError:
print("Permission denied.")
except:
print("Error occurred while copying file.")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fileworker-0.1.0.tar.gz
(1.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fileworker-0.1.0.tar.gz.
File metadata
- Download URL: fileworker-0.1.0.tar.gz
- Upload date:
- Size: 1.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.2.0-32-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5b19a0f222063422ea84bb14533ffff48bb66e0c16290fbbc1d4423534fb6a38
|
|
| MD5 |
78831559efcb7360c0f5e2c1576c4d9e
|
|
| BLAKE2b-256 |
a624659ceea2a11a2314f6ef16b63383e13c1aeea0accf195d5fcb3afe0b7002
|
File details
Details for the file fileworker-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fileworker-0.1.0-py3-none-any.whl
- Upload date:
- Size: 2.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.2.0-32-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fae4ca2b73cc7b2a0e5c6fad866ef0fb3ef7d97f740433870b25453ce8ea111b
|
|
| MD5 |
68c1ea09874eaef5b071a4c96462709b
|
|
| BLAKE2b-256 |
965ac7fd2837d01ff9bf676008c48b32c4adfccab2a4f8ec5149c2e72da9fb2a
|