Jump to content
LaunchBox Community Forums

Making .bat file to copy and rename an image


flatuswalrus

Recommended Posts

Hi all, just wondering if there was any individuals who may be able to help me. I wish to copy the image titled 1.jpg in the folder shown below and name it to match all of the folders:

image.thumb.png.4190286909a8ec9b34bc297c092d2510.png

I had a batch file I used previously to copy an image and name it the same as a bunch of .wad files I had:

for %%a in ("G:\Doom\*") do (copy "C:\Users\Dane\Pictures\Doom.jpg" "G:\Doom\%%~na.png")

I have tried to bastardize it but without success. Does anyone know how to change it to suit what I wish to do with it now? Thank you.

Link to comment
Share on other sites

@dragon57 posted an elegant answer in batch while I was in the process of writing a python script for the same purpose. I figured I might just post it anyway :)
 

from os import listdir
from os import rename
from shutil import copy

path = 'C:\\Users\\Dane\\LaunchBox\\Images'
imagefile = path + '\\1.jpg'

folders = [f for f in listdir(path)]

for folder in folders:
    try:
        copy(imagefile, path + "\\" + folder + ".jpg")
    except FileNotFoundError:
        print(folder + " was not found")
        continue

 

Edited by proghodet
  • Thanks 1
Link to comment
Share on other sites

Thank you very much both for your reply.

@dragon57 I tried it, but it did not work. Do you notice anything obviously incorrect in what I have done?:

for /d %%a in ("C:\Users\Dane\LaunchBox\Images*") do (copy "C:\Users\Dane\LaunchBox\Images\1.jpg" "%%a\%%a.jpg")

@proghodet I will have to look up what a python on script is as I have never heard of it before.

Link to comment
Share on other sites

1 hour ago, dragon57 said:

If you run my command without any edits from the Images directory, it should work fine. I have tested it here repeatedly.

How bloody silly of me, thank you so much. It sure did work. Thank you very much for your help, it is much appreciated. I tried to get my head around learning how to do it before asking but my aptitude/understanding for this kind of stuff has not quite clicked yet.

EDIT: I should have stipulated so my bad but I wanted the images to appear in the folder that 1.jpg is so I can easily cut them to paste somewhere else. I tried searching for ".jpg" in the images folder but about 27k images show up, I tried sorting by date but unfortunately I will have to pull them out of each folder manually. Silly me for not saying that.

EDIT 2: I just manually grabbed them from each folder which only took about 5 minutes. Thanks again.

Edited by Dane
Link to comment
Share on other sites

Ah, my bad, I should have explained better. Even though you got it fixed now, I'll post the instructions on how you would use it:

You would need python installed on your system. You can check if you already have it installed by opening the command prompt, and typing python --version, and pressing enter. If not, you can download it from python.org. With python installed, you can copy the code i pasted above into a text-file (using notepad or similar), save the file as copyimages.py, and then just double click the file :)

  • Thanks 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...