Skip to content

Commit 6f2635b

Browse files
committed
# _PyFiTransfer_
> _**v0.1.0** Initial Creation..._ - ***PyFiTransfer*** is a simple program developed as an easy way to transfer any number of files of a given type from one location to another. --- ## Repo Structure - Initial upload of the "***PyFiTransfer***" repository. - Initial upload of "./src/main.py" - Initial upload of "./.gitignore" - Initial upload of "./README.md" --- Signed-off-by: schlopp96 <71921821+schlopp96@users.noreply.github.com>
0 parents  commit 6f2635b

File tree

3 files changed

+324
-0
lines changed

3 files changed

+324
-0
lines changed

.gitignore

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/python
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=python
4+
5+
### Python ###
6+
# Byte-compiled / optimized / DLL files
7+
__pycache__/
8+
*.py[cod]
9+
*$py.class
10+
11+
# C extensions
12+
*.so
13+
14+
# Distribution / packaging
15+
.Python
16+
build/
17+
develop-eggs/
18+
dist/
19+
downloads/
20+
eggs/
21+
.eggs/
22+
lib/
23+
lib64/
24+
parts/
25+
sdist/
26+
var/
27+
wheels/
28+
share/python-wheels/
29+
*.egg-info/
30+
.installed.cfg
31+
*.egg
32+
MANIFEST
33+
34+
# PyInstaller
35+
# Usually these files are written by a python script from a template
36+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
37+
*.manifest
38+
*.spec
39+
40+
# Installer logs
41+
pip-log.txt
42+
pip-delete-this-directory.txt
43+
44+
# Unit test / coverage reports
45+
htmlcov/
46+
.tox/
47+
.nox/
48+
.coverage
49+
.coverage.*
50+
.cache
51+
nosetests.xml
52+
coverage.xml
53+
*.cover
54+
*.py,cover
55+
.hypothesis/
56+
.pytest_cache/
57+
cover/
58+
59+
# Translations
60+
*.mo
61+
*.pot
62+
63+
# Django stuff:
64+
*.log
65+
local_settings.py
66+
db.sqlite3
67+
db.sqlite3-journal
68+
69+
# Flask stuff:
70+
instance/
71+
.webassets-cache
72+
73+
# Scrapy stuff:
74+
.scrapy
75+
76+
# Sphinx documentation
77+
docs/_build/
78+
79+
# PyBuilder
80+
.pybuilder/
81+
target/
82+
83+
# Jupyter Notebook
84+
.ipynb_checkpoints
85+
86+
# IPython
87+
profile_default/
88+
ipython_config.py
89+
90+
# pyenv
91+
# For a library or package, you might want to ignore these files since the code is
92+
# intended to run in multiple environments; otherwise, check them in:
93+
# .python-version
94+
95+
# pipenv
96+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
97+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
98+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
99+
# install all needed dependencies.
100+
#Pipfile.lock
101+
102+
# poetry
103+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
104+
# This is especially recommended for binary packages to ensure reproducibility, and is more
105+
# commonly ignored for libraries.
106+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
107+
#poetry.lock
108+
109+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
110+
__pypackages__/
111+
112+
# Celery stuff
113+
celerybeat-schedule
114+
celerybeat.pid
115+
116+
# SageMath parsed files
117+
*.sage.py
118+
119+
# Environments
120+
.env
121+
.venv
122+
env/
123+
venv/
124+
ENV/
125+
env.bak/
126+
venv.bak/
127+
128+
# Spyder project settings
129+
.spyderproject
130+
.spyproject
131+
132+
# Rope project settings
133+
.ropeproject
134+
135+
# mkdocs documentation
136+
/site
137+
138+
# mypy
139+
.mypy_cache/
140+
.dmypy.json
141+
dmypy.json
142+
143+
# Pyre type checker
144+
.pyre/
145+
146+
# pytype static type analyzer
147+
.pytype/
148+
149+
# Cython debug symbols
150+
cython_debug/
151+
152+
# update-notes document.
153+
update-notes.md
154+
155+
# PyCharm
156+
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/
161+
162+
# End of https://www.toptal.com/developers/gitignore/api/python

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# PyFiTransfer
2+
3+
> **_Python File Transfer v0.1.0_**
4+
5+
## About
6+
7+
- **_PyFiTransfer_** is a simple program developed as a way to easily transfer files of a given extension-type from one directory to a destination directory.
8+
9+
- Came about as a personal script for moving my game screenshots to my primary "pictures" folder easily without having to manually _copy-and-paste_ after every time playing a game.
10+
11+
---
12+
13+
## Usage
14+
15+
1. To use PyFiTransfer, start by running the python script located here:
16+
17+
- `"../PyFiTransfer/src/main.py"`
18+
19+
2. Enter the file-path to the directory containing the files you wish to transfer.
20+
21+
3. Enter the file-path to the directory acting as the file transfer's destination.
22+
23+
4. Enter the file-type of the files you wish to transfer (not including the "." that proceeds the file type).
24+
25+
- Example:
26+
- You would enter (without the quotations) `"exe"` when prompted for an `".exe"` file-type.
27+
28+
5. If everything is correctly validated, a success message is returned to the console, alongside a list of files that were successfully transferred, assuming all goes well
29+
30+
- If an error occurs, the program will display an error message before exiting.
31+
32+
6. Finally, the user is prompted to press the `[ENTER]` key to exit the process.
33+
34+
---
35+
36+
## Contact
37+
38+
- If you have any questions, comments, or concerns that cannot be alleviated through the [project's GitHub repository](https://github.com/schlopp96/PyFiTransfer), please feel free to contact me through my email address:
39+
40+
- `schloppdaddy@gmail.com`
41+
42+
---

src/main.py

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#!/usr/bin/env python3
2+
#< PyFiTransfer >#
3+
#& Est. 1/15/22 $#
4+
5+
from os import PathLike
6+
from os import scandir as lsContents
7+
from os.path import basename as base
8+
from os.path import exists as isDir
9+
from shutil import move as copyfile
10+
from typing import Any
11+
12+
from loadSequence import load
13+
14+
15+
def main():
16+
origin: str | PathLike = getOrigin()
17+
destination: str | PathLike = getDestination()
18+
fileType: str | PathLike = getFileType()
19+
originClearance: bool = verify(origin)
20+
destinationClearance: bool = verify(destination)
21+
22+
if originClearance and destinationClearance:
23+
transfer(origin, destination, fileType)
24+
return Ex_0()
25+
return Ex_1(fileType)
26+
27+
28+
def getOrigin() -> str | PathLike:
29+
"""Prompt user for file-path of directory containing files to move.
30+
31+
:return: directory path of files to move.
32+
:rtype: str | PathLike
33+
"""
34+
return input(
35+
'\nPlease enter the file-path of the starting directory\'s location containing the files you wish to transfer:\n> '
36+
)
37+
38+
39+
def getDestination() -> str | PathLike:
40+
"""Prompt user for file-path of directory to move files to.
41+
42+
:return: directory path of file destination.
43+
:rtype: str | PathLike
44+
"""
45+
return input(
46+
'\nPlease enter the file-path of the directory intended to be the destination of transferred files:\n> '
47+
)
48+
49+
50+
def getFileType() -> str:
51+
"""Prompt user for type of file needing to be moved.
52+
53+
:return: file-type/extension.
54+
:rtype: str
55+
"""
56+
return input(
57+
'\nPlease enter the file-type/file-extension of the files intended to be tansferred between directory locations:\n> '
58+
)
59+
60+
61+
def verify(directory: PathLike | str) -> bool:
62+
try:
63+
if isDir(directory):
64+
load(
65+
f'\nVerifying destination for file location:\n> "{directory}"',
66+
'Directory verified successfully!', False)
67+
return True
68+
else:
69+
load(
70+
f'\nVerifying destination for file location:\n> "{directory}"',
71+
f'> ERROR\n> Directory: "{directory}"\n> Unable to be found, thus could NOT be verified.',
72+
False)
73+
return False
74+
except (OSError, ValueError, TypeError) as error:
75+
print(f'> ERROR!\n> {error}')
76+
return False
77+
78+
79+
def transfer(origin, destination, fileType) -> Any:
80+
files: list = []
81+
print('\n> Transferring files now...')
82+
with lsContents(origin) as dirFiles:
83+
for file in dirFiles:
84+
if not file.name.startswith('.') and file.name.endswith(
85+
f'.{fileType}') == True and file.is_file():
86+
files.append(file.name)
87+
88+
copyfile(file, (destination + "\\" + base(file)))
89+
load(
90+
'> Copying correct files',
91+
f'> {len(files)} files successfully copied to new location:\n{files}'
92+
)
93+
94+
95+
def Ex_0():
96+
"""Exit program with success message.
97+
98+
:return: Exits program.
99+
:rtype: NoReturn
100+
"""
101+
print('\n\nOperation Successfull!')
102+
return exit()
103+
104+
105+
def Ex_1(fileType: str):
106+
"""Exit program with error message.
107+
108+
:param fileType: file-type of files not found
109+
:type fileType: str
110+
:return: Exits program.
111+
:rtype: NoReturn
112+
"""
113+
print(
114+
f'\n\n> Operation Failure!\n\n> No Files were found with given extension: ".{fileType}".\n'
115+
)
116+
return exit()
117+
118+
119+
if __name__ == "__main__":
120+
main()

0 commit comments

Comments
 (0)