EvilZone
Programming and Scripting => Scripting Languages => : Kulverstukas August 27, 2011, 10:32:30 AM
-
Made a script to do the long work for me. This script takes a dir and renames every file with an increasing number so that the folder would look more clean. Extension is left, only the name is changed.
Second line must be changed to your directory that you want to rename files in.
import os
dir = 'dirname'
Num = 0
for Item in os.listdir(dir):
Num += 1
(name, ext) = os.path.splitext(Item)
os.rename(dir+'/%s' % Item, dir+'/%d%s' % (Num, ext))
-
A while ago my friend gave me thousands of legacy game system ROM's; each in it's own zip file. I wrote this script to take care of unzipping all of them. Really messy, and could use some optimization, but it worked. Thought about making a GUI, but meh.
import zipfile, os
print """=-=-=-=-=-=-=--=MASS_ZIP_EXTRACTION=-=-=-=-=-=-=--=
=-=-=-=-=-=-=-=-By: Tech B. =-=-=-=-=-=-=-=-=-=-="""
print """
"""
d = raw_input("""Path to Directory containing the Zip's to be extracted
example: C:\\Users\\TechB\\Desktop\\Zips
:""")
unzipFolder = raw_input("""Folder to place unzipped files: """)
zList = os.listdir(d)
badList = []
gnt = 0
bnt = 0
allz = 0
for z in zList:
try:
di = d
di += '\\' + z
if zipfile.is_zipfile(di) == True:
x = zipfile.ZipFile(di)
x.extractall(unzipFolder)
gnt += 1
allz += 1
print "extracted: ", z, gnt
else:
bnt += 1
allz += 1
badList.append(z)
print "failed: ", z, bnt
except:
allz += 1
badList.append(z)
print 'Error: ', z
print "=-=-=-=-=-=-==-=-=-=-=-=-="
print "Total files: %d" % allz
print "=-=-=-=-=-=-=-==-=-=-=-=-="
print "Failed files:"
for i in badList:
print i
-
A while ago my friend gave me thousands of legacy game system ROM's; each in it's own zip file. I wrote this script to take care of unzipping all of them. Really messy, and could use some optimization, but it worked. Thought about making a GUI, but meh.
Why not post it in a separate thread?
-
It kind of follows what you did. Working with the file directory's, and mass file manipulation. Just thought it would be appropriate in this thread.
-
why not ask the user which folder he wants to work ?
example :
dir = str(input('Type a dirname > '))
This will simplify the use of the script (no need to modify every time)