Advertisement
rfmonk

Untitled

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