darko3 / batch-renamer Goto Github PK
View Code? Open in Web Editor NEWAn easy to use python script for quickly renaming multiple files with incrementing numbers.
License: MIT License
An easy to use python script for quickly renaming multiple files with incrementing numbers.
License: MIT License
A few comments from glancing over your source:
#!/usr/bin/python
: You need to specify a python version. This won't point to Python 2 on all linux distros.
--help\t\t\t\tprint
: Tab escape keys make your docstring harder to read. Just insert actual tabs or spaces instead.
self.license_agree != "yes" or "y" or "n" or "no"
: This will always return True because False or "y" == True
. The proper solution for is:
any(self.license_agree in ('yes', 'y', 'no', 'n'))
os.mkdir("%s/.batch-renamer-cli" % home)
: It's poor form to dump your configuration/temp files in the current directory. (At least for linux) see:
from gi.repository import GLib
GLib.get_user_data_dir()
GLib.get_user_cache_dir()
GLib.get_user_config_dir()
Enclosing your print statements in parenthesis will go a long way towards working with both python 2 and 3.
print "Finished renaming %s files with a total time of %s seconds." % (self.file_counter, total_time)
: Neither of these variables are strings, you should use the appropriate formatting flags %d and %f.
end = time.time()
: On windows, time.clock() is much more accurate. (On linux time.clock() is straight up wrong though).
enter_to_continue = raw_input(...
: this should be split into lines at each \n
for readability.
sys.exit(0)
: An exit status of 0 means success. You should be exiting with a non-zero status for errors.
The MIT license doesn't permit the notice to be removed but you've made it an integral active part of the program. It should be reproduced in a comment at the top of the file. This will make it easier for others to modify your code without violating your license.
class Main():
: you aren't using this as a class, so it doesn't need to be a class. This would suffice:
def main():
myName = 'hello world'
def rename():
RENAME_FUNCTION(myName)
Or even better, get rid of the global variables:
def rename(old_name, new_name):
# ...
def main():
myName = 'hello wrold'
rename(myName, 'hello world')
In general, passing values as function arguments is better than relying on a single variable to hold all your parameters.
elif self.license_agree == "yes":
replace that elif
with a simple if
and you no longer need to duplicate code in the preceding if statement.for file in files:
in python 2, file
is a preexisting type variable.try: ... except OSError
to only the lines that can produce that error. Also, this can be an important error when renaming files, make it known to the user when this error is raised unless you specifically expect it in a particular place.C:\Users\Vartotojas\batch-renamer>batch-rename.py -h Requested Python version (2) is not installed
I have an error that require Python version (2). How to run with Python 3.6?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.