forked from thomaskellough/Automate-The-Boring-Stuff
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPy Copy.py
More file actions
29 lines (24 loc) · 1.09 KB
/
Copy pathPy Copy.py
File metadata and controls
29 lines (24 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#! python3
# py copy - copies your .py file into MyPythonScripts
import shutil
# User input for which file to move and from where
pyfile = input('Which .py file would you like to copy?\n')
location = input('Where is the .py located?\n')
# Creates paths for copying the file to the new directory
old_location = location + '\\' + pyfile + '.py'
new_location = 'C:\MyPythonScripts' + '\\' + pyfile + '.py'
# Copies the .py file to the new directory
print('Copying file...')
shutil.copy(old_location, new_location)
print('Successfully copied ' + pyfile + ' .py to MyPythonScripts.')
# Creates a .bat file so program can be run from win+R
print('Creating ' + pyfile + '.bat...')
text = '@py.exe C:\MyPythonScripts\\' + pyfile + '.py %*\n@pause'
bat_file = open('C:\MyPythonScripts\\' + pyfile + '.txt', 'w')
bat_file.write(text)
bat_file.close()
# Convert .txt to .bat file
old_suffix = pyfile + '.txt'
new_suffix = pyfile + '.bat'
shutil.move('C:\MyPythonScripts\\' + old_suffix, 'C:\MyPythonScripts\\' + new_suffix)
print('Successfully created ' + pyfile + ' .bat to MyPythonScripts')