-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSaveCopyAs.py
More file actions
30 lines (24 loc) · 879 Bytes
/
SaveCopyAs.py
File metadata and controls
30 lines (24 loc) · 879 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
28
29
30
import sublime, sublime_plugin
import datetime
import shutil
import os.path
class SaveCopyAsCommand(sublime_plugin.TextCommand):
def run(self, edit):
fileName = self.view.file_name()
if fileName == None:
sublime.error_message("You have to save the file first!")
return
now = datetime.datetime.now()
now = now.strftime("%Y%m%d")
newFileName = fileName + "." + now;
self.view.window().show_input_panel("Copy File Name:", newFileName, self.save_copy, None, None)
def save_copy(self, newFilePath):
filePath = self.view.file_name()
if filePath == None:
return
FilePathTemp = newFilePath
i = 0
while os.path.isfile(newFilePath):
i += 1
newFilePath = FilePathTemp + "_" + str(i)
shutil.copy2(filePath, newFilePath)