SHOW:
|
|
- or go back to the newest paste.
| 1 | - | #!/usr/bin/env python |
| 1 | + | #!/usr/bin/env python |
| 2 | - | |
| 2 | + | |
| 3 | - | |
| 3 | + | |
| 4 | - | """ |
| 4 | + | """ |
| 5 | - | ##These aproaches didin't work## |
| 5 | + | ##These aproaches didin't work## |
| 6 | - | I'm trying to replace a file that looks like |
| 6 | + | I'm trying to replace a file that looks like |
| 7 | - | socketpair.c-3ymvNUZH.txt and strip all the chars |
| 7 | + | socketpair.c-3ymvNUZH.txt and strip all the chars |
| 8 | - | after the extension so it looks like socketpair.c |
| 8 | + | after the extension so it looks like socketpair.c |
| 9 | - | |
| 9 | + | |
| 10 | - | import os |
| 10 | + | import os |
| 11 | - | import sys |
| 11 | + | import sys |
| 12 | - | |
| 12 | + | |
| 13 | - | for filename in os.listdir(os.path.dirname(os.path.abspath(__file__))): |
| 13 | + | for filename in os.listdir(os.path.dirname(os.path.abspath(__file__))): |
| 14 | - | base_file, ext = os.path.splitext(filename) |
| 14 | + | base_file, ext = os.path.splitext(filename) |
| 15 | - | if ext == ".c-": |
| 15 | + | if ext == ".c-": |
| 16 | - | os.rename(filename, base_file + ".c") |
| 16 | + | os.rename(filename, base_file + ".c") |
| 17 | - | |
| 17 | + | |
| 18 | - | |
| 18 | + | |
| 19 | - | |
| 19 | + | |
| 20 | - | import glob |
| 20 | + | import glob |
| 21 | - | import os |
| 21 | + | import os |
| 22 | - | |
| 22 | + | |
| 23 | - | for filename in glob.iglob(os.path.join('/home/rfmonk/Source/', '.c-*')): |
| 23 | + | for filename in glob.iglob(os.path.join('/home/rfmonk/Source/', '.c-*')):
|
| 24 | - | os.rename(filename, filename[:-12] + '.c') |
| 24 | + | os.rename(filename, filename[:-12] + '.c') |
| 25 | - | |
| 25 | + | |
| 26 | - | """ |
| 26 | + | """ |
| 27 | - | |
| 27 | + | |
| 28 | - | #! /usr/bin/env python |
| 28 | + | #! /usr/bin/env python |
| 29 | - | |
| 29 | + | |
| 30 | - | |
| 30 | + | |
| 31 | - | import subprocess |
| 31 | + | import subprocess |
| 32 | - | import argparse |
| 32 | + | import argparse |
| 33 | - | import re |
| 33 | + | import re |
| 34 | - | |
| 34 | + | |
| 35 | - | # Parse command line arguments. |
| 35 | + | # Parse command line arguments. |
| 36 | - | # Run a Bash command and send output to a list seperated by line. |
| 36 | + | # Run a Bash command and send output to a list seperated by line. |
| 37 | - | # Change name function |
| 37 | + | # Change name function |
| 38 | - | |
| 38 | + | |
| 39 | - | |
| 39 | + | |
| 40 | - | def changeName(oldName, newNameBase): |
| 40 | + | def changeName(oldName, newNameBase): |
| 41 | - | temp = re.split('([0-9]+)', oldname) |
| 41 | + | temp = re.split('([0-9]+)', oldname)
|
| 42 | - | newName = newNameBase + temp[1] + temp[2] |
| 42 | + | newName = newNameBase + temp[1] + temp[2] |
| 43 | - | subprocess.call(["mv", oldName, newName]) |
| 43 | + | subprocess.call(["mv", oldName, newName]) |
| 44 | - | |
| 44 | + | |
| 45 | - | |
| 45 | + | |
| 46 | - | # Change names of all files matching base |
| 46 | + | # Change names of all files matching base |
| 47 | - | def changeAllNames(oldNameBase, newNameBase): |
| 47 | + | def changeAllNames(oldNameBase, newNameBase): |
| 48 | - | files = runBash("ls") |
| 48 | + | files = runBash("ls")
|
| 49 | - | for afile in files: |
| 49 | + | for afile in files: |
| 50 | - | temp = re.split('([0-9]+)', afile) |
| 50 | + | temp = re.split('([0-9]+)', afile)
|
| 51 | - | if temp[0] == oldNameBase: |
| 51 | + | if temp[0] == oldNameBase: |
| 52 | - | changeName(afile, newNameBase) |
| 52 | + | changeName(afile, newNameBase) |
| 53 | - | |
| 53 | + | |
| 54 | - | # Change files with base inputFileName to base outputFileName |
| 54 | + | # Change files with base inputFileName to base outputFileName |
| 55 | - | # changeAllNames(args.inputFileName,args.outputFileName) |
| 55 | + | # changeAllNames(args.inputFileName,args.outputFileName) |
| 56 | - | changeAllNames(args.'*.c-*', args.'*.c') |
| 56 | + | changeAllNames("args.find -type f -name *.c*", args.'*.c')
|
| 57 | ||
| 58 | # grrr back to the drawing board |