I'm trying to make a program that will take a file, say my_test_file.log and make a new file called my_test_file.mdn. I'd like to be able to use this program by typing python renameprogram.py my_test_file.log into the command line. The original file will always end in .log.
-
In addition to the above link, take a look at docs.python.org/2/library/sys.html#sys.argv and docs.python.org/2/library/os.html#os.renameAMacK– AMacK2015-04-29 02:41:42 +00:00Commented Apr 29, 2015 at 2:41
Add a comment
|
2 Answers
You certainly can create a Python program that will accomplish this, but there are shell level commands that already do this.
For Linux/Unix:
mv my_test_file.log my_test_file.mdn
For Windows (see this link):
rename my_test_file.log my_test_file.mdn
4 Comments
Joran Beasley
I believe you could even do
mv *.log *.mdn (+1)dscripka
If you want to rename all files in the current directory, yes.
dhenness
I know I can do this with unix, but the reason I'd like to do it in python is because I need to get a bunch of other data from the original file and put it into the new file in a different format I'd like to do this all with one program if possible, but that might be beyond my skills at the moment haha. This is just the first step.
user2357112
@JoranBeasley: No, that wouldn't be the correct syntax. The
*.mdn wouldn't expand to what you want it to expand to, and mv would complain about the target not being a directory.