Thursday, July 30, 2009

I want a program for Win/Linux 2 duplicate a file and assign it a name according to a supplied name list file.

It would have the syntax of something like this:





C:\Duplicator%26gt;duplirename.exe -source C:\file.txt -outputdir C:\newfiles\ -namelist C:\namelist.txt





Where duplirename.exe is the command, -source [file] specifies the file to be duplicated, -outputdir [dir] specifies a directory to create the new files in and -namelist [file] specifies the name list file.





The namelist.txt would be a simple text file with a new name on each new line, so if the namelist.txt looked like this:





bob


jim


happy





after running the command, the output directory would look like this:





C:\newfiles%26gt;dir


bob.txt


jim.txt


happy.txt





I hope this makes sense. I need it for work, and we use Windows machines, but I could probably do at home on my Linux box - if that would be easier. Thanks for all your help!

I want a program for Win/Linux 2 duplicate a file and assign it a name according to a supplied name list file.
#!/usr/bin/env python





import shutil





source = open("source.txt")


dest = open("dest.txt")





for (name,newname) in zip(source.readlines(), dest.readlines()):


%26lt;tab%26gt;name = name.split("\n")[0]


%26lt;tab%26gt;newname = newname.split("\n")[0]


%26lt;tab%26gt;shutil.move(name, newname)





-----------------


use this python script. I suppose that it will run nice in both systems (win and linux)





You can improve it to handle your command line options. I have used default source.txt and dest.txt filenames just for keeping it simple.





You will need a python interpreter (usually pré-installed on linux, but not on windows) If you dont have a python interpreter, download it at the link provided below:
Reply:Perhaps I'm missing something... I don't see how you define what the original file name is and what you want it to be named as.


No comments:

Post a Comment