Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- """
- ##These aproaches didin't work##
- I'm trying to replace a file that looks like
- socketpair.c-3ymvNUZH.txt and strip all the chars
- after the extension so it looks like socketpair.c
- import os
- import sys
- for filename in os.listdir(os.path.dirname(os.path.abspath(__file__))):
- base_file, ext = os.path.splitext(filename)
- if ext == ".c-":
- os.rename(filename, base_file + ".c")
- import glob
- import os
- for filename in glob.iglob(os.path.join('/home/rfmonk/Source/', '.c-*')):
- os.rename(filename, filename[:-12] + '.c')
- """
- #! /usr/bin/env python
- import subprocess
- import argparse
- import re
- # Parse command line arguments.
- # Run a Bash command and send output to a list seperated by line.
- # Change name function
- def changeName(oldName, newNameBase):
- temp = re.split('([0-9]+)', oldname)
- newName = newNameBase + temp[1] + temp[2]
- subprocess.call(["mv", oldName, newName])
- # Change names of all files matching base
- def changeAllNames(oldNameBase, newNameBase):
- files = runBash("ls")
- for afile in files:
- temp = re.split('([0-9]+)', afile)
- if temp[0] == oldNameBase:
- changeName(afile, newNameBase)
- # Change files with base inputFileName to base outputFileName
- # changeAllNames(args.inputFileName,args.outputFileName)
- changeAllNames("args.find -type f -name *.c*", args.'*.c')
- # grrr back to the drawing board
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement