| 1 |
nino.borges |
316 |
"""This is for a project where they wanted to rename a bunch of files with data from the database.
|
| 2 |
|
|
I had to export a file of BEGNO|filename, so that I could cross ref below???
|
| 3 |
|
|
|
| 4 |
|
|
for f in os.listdir(r"C:\Test_dir\davita\binder003\binder003\Documents\c_d"):
|
| 5 |
|
|
... filename = "2013_022013_" + f.split(" - ")[0] + " - " + matrix[f.split(" - ")[0]]
|
| 6 |
|
|
... if ":" in filename:
|
| 7 |
|
|
... filename = filename.replace(":","")
|
| 8 |
|
|
... if "?" in filename:
|
| 9 |
|
|
... filename = filename.replace("?","")
|
| 10 |
|
|
... if "/" in filename:
|
| 11 |
|
|
... filename = filename.replace("/","")
|
| 12 |
|
|
... os.rename(os.path.join(r"C:\Test_dir\davita\binder003\binder003\Documents\c_d",f),os.path.join(r"C:\Test_dir\davita\binder003\binder003\Documents", filename))
|
| 13 |
|
|
...
|
| 14 |
|
|
"""
|
| 15 |
|
|
----
|
| 16 |
|
|
"""This is an updated version"""
|
| 17 |
|
|
matrix = {}
|
| 18 |
|
|
>>> contents = open(r"\\bstads01\app\Manny\Client\39323308\20130308_INT_BANK_PDFS\BOA_INT_BANK.DAT").readlines()
|
| 19 |
|
|
>>> for line in contents:
|
| 20 |
|
|
... line = line.replace("\n","")
|
| 21 |
|
|
... bates,fname,dte = line.split("|")
|
| 22 |
|
|
... matrix[bates] = fname
|
| 23 |
|
|
...
|
| 24 |
|
|
>>> for f in os.listdir(r"\\bstads01\app\Manny\Client\39323308\20130308_INT_BANK_PDFS\OLD\Bateman"):
|
| 25 |
|
|
... filename = "2013_032013_" + os.path.splitext(f)[0] + " - " + matrix[os.path.splitext(f)[0]]
|
| 26 |
|
|
... if ":" in filename:
|
| 27 |
|
|
... filename = filename.replace(":","")
|
| 28 |
|
|
... if "?" in filename:
|
| 29 |
|
|
... filename = filename.replace("?","")
|
| 30 |
|
|
... if "/" in filename:
|
| 31 |
|
|
... filename = filename.replace("/","")
|
| 32 |
|
|
... if "," in filename:
|
| 33 |
|
|
... filename = filename.replace(",","")
|
| 34 |
|
|
... if "\\" in filename:
|
| 35 |
|
|
... filename = filename.replace("\\","")
|
| 36 |
|
|
... os.rename(os.path.join(r"\\bstads01\app\Manny\Client\39323308\20130308_INT_BANK_PDFS\OLD\Bateman",f),os.path.join(r"\\bstads01\app\Manny\Client\39323308\20130308_INT_BANK_PDFS\NEW\Bateman", filename+".PDF"))
|
| 37 |
|
|
...
|
| 38 |
|
|
"""This one is one where there are multiple subfolders, instead on on big folder"""
|
| 39 |
|
|
>>> contents = open(r"\\bstads01\app\Manny\Client\39323308\Binder013\Native Export 3-12-2013\Native Export.DAT").readlines()
|
| 40 |
|
|
|
| 41 |
|
|
>>> for line in contents:
|
| 42 |
|
|
... line = line.replace("\n","")
|
| 43 |
|
|
... bates,fname,dte = line.split("|")
|
| 44 |
|
|
... matrix[bates] = fname
|
| 45 |
|
|
>>> matrix = {}
|
| 46 |
|
|
>>> for line in contents:
|
| 47 |
|
|
... line = line.replace("\n","")
|
| 48 |
|
|
... bates,fname,dte = line.split("|")
|
| 49 |
|
|
... matrix[bates] = fname
|
| 50 |
|
|
...
|
| 51 |
|
|
>>> for folder in os.listdir(r"\\bstads01\app\Manny\Client\39323308\Binder013\Native Export 3-12-2013"):
|
| 52 |
|
|
... if os.path.isdir(os.path.join(r"\\bstads01\app\Manny\Client\39323308\Binder013\Native Export 3-12-2013",folder)):
|
| 53 |
|
|
... for f in os.listdir(os.path.join(r"\\bstads01\app\Manny\Client\39323308\Binder013\Native Export 3-12-2013",folder)):
|
| 54 |
|
|
... filename = "2013_032013_" + os.path.splitext(f)[0] + " - " + matrix[os.path.splitext(f)[0]]
|
| 55 |
|
|
... if ":" in filename:
|
| 56 |
|
|
... filename = filename.replace(":","")
|
| 57 |
|
|
... if "?" in filename:
|
| 58 |
|
|
... filename = filename.replace("?","")
|
| 59 |
|
|
... if "/" in filename:
|
| 60 |
|
|
... filename = filename.replace("/","")
|
| 61 |
|
|
... if "," in filename:
|
| 62 |
|
|
... filename = filename.replace(",","")
|
| 63 |
|
|
... if "\\" in filename:
|
| 64 |
|
|
... filename = filename.replace("\\","")
|
| 65 |
|
|
... if os.path.exists(os.path.join(r"\\bstads01\app\Manny\Client\39323308\Binder013\NEW",folder)):
|
| 66 |
|
|
... pass
|
| 67 |
|
|
... else:
|
| 68 |
|
|
... os.makedirs(os.path.join(r"\\bstads01\app\Manny\Client\39323308\Binder013\NEW",folder))
|
| 69 |
|
|
... os.rename(os.path.join(os.path.join(r"\\bstads01\app\Manny\Client\39323308\Binder013\Native Export 3-12-2013",folder),f),os.path.join(os.path.join(r"\\bstads01\app\Manny\Client\39323308\Binder013\NEW",folder),filename+".PDF")) |