help me to create a batch file

June 13, 2011 at 09:57:32
Specs: Windows 7/Windows XP
Hi, I have an jpg file and a txt file that contais a list of names (one name per line). What I want to do is to copy the logo.jpg file in a folder with a name given from the list.txt

It would be like this:

create folder->copy logo.jpg->rename to NameFromLineOne.jpg->restart loop->copy logo.jpg->rename to NameFromLineTwo.jpg.......

I want to put all the commands in a batch file. If is needed I can install SED and GREP, but this is not the place to ask about that.

Thanks for the help.

See More: help me to create a batch file

Report •

June 13, 2011 at 15:21:01
From your post I gathered that you want multiple files with the same content. You haven't shown whether or not logo.jpg and list.txt exist in the same path so you will have to amend the paths I chose if necessary.

@echo off

if not exist %temp%\rubbish\ md %temp%\rubbish

for /f "tokens=*" %%1 in (%temp%\list.txt) do (
    copy %temp%\logo.jpg %temp%\rubbish\%%1>nul

Please come back & tell us if your problem is resolved.

Report •

June 13, 2011 at 18:34:40
Thanks Wahine, that worked just fine. Yes logo.jpg and list.txt are in the same folder.

Now I'll analyse the code, so I can understand it.

And if I want to do it like this, it doesn't work:

@echo off

set rar=%ProgramFiles(x86)%\WinRAR\RAR.exe
if not exist E:\test\rubbish\ md E:\test\rubbish

for /f "tokens=*" %%1 in (E:\test\list.txt) do (
copy E:\test\logo.jpg E:\test\rubbish\%%1>nul
%rar% a "E:\test\rubbish\" "E:\test\rubbish\%%1"


I also want to add every archive created in rubbish to be added to a .rar for every new file. I use windows 7 and I also have 7zip.

Report •

June 13, 2011 at 23:52:41
Sorry, my experience of file compression is sadly lacking but I believe there's not much point in compressing .jpg files as they don't lend themselves to it.

Perhaps another member can advise both of us about compressing .jpg's, here's hoping.

Please come back & tell us if your problem is resolved.

Report •

Related Solutions

Ask Question