-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path_copy_file.py
More file actions
27 lines (23 loc) · 833 Bytes
/
_copy_file.py
File metadata and controls
27 lines (23 loc) · 833 Bytes
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
#!python3
'''Coded to be used inside Pythonista app.
Add this script to the action menu of the editor to use. Run the script while
the file to copy is currently opened in the editor.'''
import console
import editor
import os
import shutil
def numbered_filename(filename):
if os.path.exists(filename):
i = 2
numbered_name = ('(' + str(i) + ')').join(os.path.splitext(filename))
while os.path.exists(numbered_name):
i += 1
numbered_name = ('(' + str(i) + ')').join(os.path.splitext(filename))
return numbered_name
def main():
file_path = editor.get_path()
write_path = numbered_filename(os.path.split(file_path)[-1])
shutil.copy(file_path, write_path)
console.hud_alert('Copied as: {}'.format(write_path), duration=.75)
if __name__ == '__main__':
main()