Skip to content

Commit a3839b9

Browse files
authored
Merge pull request #1 from Bulls90/develop
Develop
2 parents 86e5cca + bb3466a commit a3839b9

File tree

1 file changed

+60
-16
lines changed

1 file changed

+60
-16
lines changed

WorkingWithFiles.py

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# !/usr/bin/python3
22
# coding: utf8
33
# @author Bulls90
4-
# v3.1
4+
# v4.1
55
# Importing modules
66
import os
77
import shutil
@@ -11,20 +11,21 @@
1111
src = input('Please indicate the path of the input files: ')
1212
dest = input('Please indicate the path to leave the files: ')
1313

14-
if src:
15-
print('The route of entry is: ' + src)
16-
else:
17-
sys.exit('¡You must enter an inbound route! Ending program...')
18-
if dest:
19-
print('The exit route is: ' + dest)
20-
else:
21-
sys.exit('¡You must indicate an exit route! Ending program...')
14+
if src == '':
15+
sys.exit("""
16+
*******************************************************
17+
* ¡You must indicate a source path! Ending program... *
18+
*******************************************************""")
19+
if dest == '':
20+
sys.exit("""
21+
************************************************************
22+
* ¡You must indicate a destination path! Ending program... *
23+
************************************************************""")
2224

23-
os.chdir(dest)
2425

25-
26-
# Creates folders by file name, and then moves the files to the corresponding folder
27-
def classify():
26+
# Creates folders by file name, and then moves the files to the corresponding folder changing filenames.
27+
def classify_new_name():
28+
os.chdir(dest)
2829
for f in os.listdir(src):
2930
splitname = f.split('_')
3031
status = splitname[1]
@@ -43,6 +44,49 @@ def classify():
4344
shutil.move(os.path.join(src, f), newFileName)
4445

4546

46-
print('Sorting out files, please wait...')
47-
classify()
48-
print('¡DONE!')
47+
# Creates folders by file name, and then moves the files to the corresponding folder keeping original filenames.
48+
def classify():
49+
os.chdir(dest)
50+
for f in os.listdir(src):
51+
splitname = f.split('_')
52+
status = splitname[1]
53+
topic = splitname[2]
54+
foldername = topic + '_' + 'Status_' + status
55+
if not os.path.exists(foldername):
56+
os.mkdir(foldername)
57+
shutil.move(os.path.join(src, f), foldername)
58+
59+
60+
def question():
61+
option = str
62+
option = (input("""
63+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
64+
|Choose one of the following options: |
65+
| (a) Keeping original file name |
66+
| (b) Rename files |
67+
| (c) Exit |
68+
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
69+
Chosen option:""") + option())
70+
if option == 'a':
71+
print('Sorting out keeping the original name of the files, please wait...')
72+
classify()
73+
print('¡Finalizado!')
74+
elif option == 'b':
75+
print('Shorting out and renaming file names, please wait...')
76+
classify_new_name()
77+
print('¡Done!')
78+
else:
79+
if option == '':
80+
print('¡ERROR! No option has been chosen')
81+
question()
82+
elif option == 'c':
83+
sys.exit('Closing tool...See you later.!')
84+
elif option != 'a' or 'b' or 'c':
85+
print("""
86+
!!!!!!!!!!!!!!!!!!!!!!!!!
87+
! INCORRECT VALUE ENTERED !
88+
!!!!!!!!!!!!!!!!!!!!!!!!!""")
89+
question()
90+
91+
92+
question()

0 commit comments

Comments
 (0)