Created
February 25, 2015 21:52
-
-
Save jmasselink/2ac794f6a2cdc8b90017 to your computer and use it in GitHub Desktop.
rename files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = 't-joelm' | |
import glob, os | |
import csv | |
def rename(dir, pattern, titlePattern) | |
for pathAndFilename in glob.iglob(os.path.join(dir, pattern)): | |
title, ext = os.path.splitext(os.path.basename(pathAndFilename)) | |
os.rename(pathAndFilename, | |
os.path.join(dir, titlePattern % title + ext)) | |
rename(r'c:\temp\xx', r'*.doc', r'new(%s)') | |
input = open("f:\input.csv", 'r') # 'rb' for binary | |
output = open("f:\output.csv", 'w') # 'wb' for binary | |
os.rename(arg[0], arg[1]) | |
path = r'C:\Users\T-JoelM\Documents\GEC\paes_data\ZWE_MAT\normalized\flights' ##define path | |
input = open("f:\input.csv", 'r') # 'rb' for binary | |
output = open("f:\output.csv", 'w') # 'wb' for binary | |
csv_in = csv.reader(input) | |
csv_out = csv.writer(output) | |
next(csv_in, None) # skip first row | |
for row in csv_in: | |
new_id = "{0}{1}/{2}".format( | |
'S' if float(row[2]) < 0 else 'N', | |
abs(float(row[2])), | |
row[1]) # use "".format() and you can skip all the str(), etc ... and I think its easier to read too. | |
output = [new_id] | |
output.extend(row[1:]) # [1:] will return everything in the list starting at the second element | |
csv_out.writerow(output) | |
for f in glob.glob('*.kml'): | |
new_filename = f.replace("-","_") | |
new_filename = "kml_" + new_filename | |
os.rename(f,new_filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment