English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

It would have the syntax of something like this:

C:\Duplicator>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>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!

2007-01-28 17:52:41 · 2 answers · asked by Josh F 1 in Computers & Internet Programming & Design

2 answers

#!/usr/bin/env python

import shutil

source = open("source.txt")
dest = open("dest.txt")

for (name,newname) in zip(source.readlines(), dest.readlines()):
name = name.split("\n")[0]
newname = newname.split("\n")[0]
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:

2007-02-05 14:26:06 · answer #1 · answered by juca_blues 2 · 0 0

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.

2007-01-28 18:03:51 · answer #2 · answered by BigRez 6 · 0 0

fedest.com, questions and answers