-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_batch.py
40 lines (30 loc) · 960 Bytes
/
make_batch.py
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
31
32
33
34
35
36
37
38
39
40
# -*- coding: utf-8 -*-
"""
Created on Sun May 10 12:28:29 2020
@author: Aamod Pant
"""
import sys
import os
#save command line argument as name of the file to create file
batname=sys.argv[1] #batch file name to create
# batname='testfile'
#IMPORTANT: Replace this file path to your environment location
content='@ py C:\\Aamod\\Python_Programs\\py_files\\ %*'
print("Add pause? y/n")
answer=input()
if(answer.lower()=="y"):
content=content+'\n@ pause'
# creating content for batch file
breakpoint=content.index('%')-1
content= content[:breakpoint]+batname+'.py'+content[breakpoint:]
path= content[5: (content.rindex('\\py_files'))+1]+batname+'.bat'
print(path)
#creating batch file, and checking if file exists
if not os.path.exists(path):
newf= open(path, 'w+')
newf.write(content)
newf.close()
print("File created")
else:
print('File already exists')
#Batch file created