Thanks briarfox, I'll check out StaSh.
I noticed my script wouldn't increment correctly if a file ending in a higher number already existed. For example, if I've got the files a1, a2, a3 and use the script on a2, it would give me "a3 1".
I've attempted to fix this and it seems to be working but the code is not at all elegant. Any tips on easier ways to do this? Again, I'm really new to this so sorry for the crazy code! I don't really know what I'm doing. I also noticed it doesn't work in folders, but that's for another day.
Here's the code:
import os, sys, editor, re
filepath = editor.get_path()
filename = os.path.basename(filepath)
ext1 = os.path.splitext(filepath)
noext = filename[:-len(ext1)-1]
noextnonum = re.split('([0-9]+)$',noext)[0]
namelen = len(noextnonum)
#filepath stuff
path = os.path.dirname(filepath)
#editor.reload_files()
files = os.listdir(path)
text = editor.get_text()
if not text:
sys.exit('No text in the Editor.')
alist = []
x = 0
while x<=len(files)-1:
if noextnonum == files[x][:namelen]:
ext = os.path.splitext(files[x])[1]
noext = files[x][:-len(ext)]
try:
num = re.split('([0-9]+)$',noext)[1]
alist.append(int(num))
filename = noextnonum + str(max(alist)+1) + ext
except:
filename = noextnonum + str(1) + ext
x = x + 1
editor.make_new_file(filename, text)