Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi
I really need some help to do what I thought would be a simple task. I am a real n00b when it comes to programming, but have now spent many hours trying to get this to work....without success :(
The task:
1) I have a folder that contains about 200 files. Each of these files is a picture, and is named in the following format xxxxxxxxxx_64.png
2) I have another file called logo.png in another folder. All the files in the first folder need to display the logo picture, but retain their original name.The end result should be mutliple copies of logo.png, but all will be called different names as set out by the files in the first folder.
I know it may sound like a daft task, but it is an IMPORTANT one, and needs to be done a few times a week. Each time having to be done by hand so far, which is most boring.
Any ideas, assistance or known scripts to help?
I have exported all the filenames into a text file, and then tried to read in the names from there, but got nowhere :(

Lets see if i understood this right...
You then want 200 copies of logo.png, but ever copy should should be named after each file in folder1 (xxxxxxxxxx_64.png)?Ok, lets assume folder 1 is located at
c:\folder1
and folder2 in c:\folder2Copy&paste the code in notepad (edit paths as you like).
Save the file as a .bat or .cmd fileNOTE: The code should work, but i didnt test it, so try it on copies of your folders first.
::-----CODE-----
::Make a list of all files(names) in folder1
dir /b "c:\folder1" >>filelist.txt::Goes trough every line in filelist
:: %%i contains the filename
for /f %%i in (filelist.txt) do
(
copy "c:\folder2\logo.png" "c:\folder2\%%i"
)
del filelist.txt
::------CODE------

"I know it may sound like a daft task, but it is an IMPORTANT one"
Sounds like the story of my life.
This should get you on the right track:
::== logo.bat
@echo off
if not exist F1 md F1
if not exist F2 md F2
for /L %%N in (1 1 5) do type nul > F1\%%N.png
> F2\logo.png echo this is logo
for /f %%F in ('dir/b/s F1\*.png') do (
copy /b F2\logo.png %%F > nul
)
:: DONE
=====================================
If at first you don't succeed, you're about average.M2

I guess I need to type faster; or think faster.
LOL
=====================================
If at first you don't succeed, you're about average.M2

The first program I kind of understand, but it throws a syntax error:
C:\LIH>dir /b "c:\LIH\portraits" >filelist.txt
The syntax of the command is incorrect.
C:\LIH>for /f %i in (filelist.txt) doThe second program looks scary, but I am trying it now :)

Hmm.. Did you run it from a batch, or did you try to type in the commands manually?
Paste the code in notepad and save the file as a .batI rewrote the script to match your folders, and it works for me.
Test case:
I created:
c:\LIH
c:\LIH\portraits
c:\LIH\folder2/portraits contains pictures
/folder2 contains logo.png
/tmp folder will contain the renamed copies::------CODE-----
@echo off
md c:\lih\tmp
dir /b "c:\LIH\portraits" >>filelist.txt
for /f %%i in (filelist.txt) do (
copy "c:\LIH\folder2\logo.png" "c:\LIH\tmp\%%i"
)
del filelist.txt
::------CODE-----Anyway, im sure both scripts does the same job. Its just two different aproaches.

works a treat, thanks :-))
Not sure what the difference was to the first program I tried, I must have copied a typo in somehow that I just could not find to correct.
Thanks a million.
I shall now fiddle to my hearts content :-))

It just came to mind while looking at M2's code, that you dont need to write the Dir to a file first.
Here's sum improved code:
::----CODE----
md c:\lih\tmp
for /f "tokens=*" %%i in ('dir/b "c:\lih\portraits"') do (
copy "c:\LIH\folder2\logo.png" "c:\LIH\tmp\%%i"
)
::----CODE----
M2: Ive noticed that after i runned this one, i cannot delete the TMP folder as Windows says its in use (by explorer i noticed). This problems seems to occur while using the FOR command with ('command').
Have you any idea why this occurs?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |