Copy an image and rename it to match other file names - image

I have ZERO bat knowledge so thought I would ask here, if I may.
I have an image C:\Users\Dane\Pictures\Doom.jpg. I wish for this image to be copied and for it to be renamed to the exact name of 379 non-image type files which are in another folder which is G:\Doom. So I will have the same image 379 times but named to match the 379 files.
Would anyone be kind enough to write a bat file to do that? Thank you in advance.

This site is not a free code writing service; Rather give the subject an attempt and we will be happy to assist you. However, because I'm nice, I have a response for you.
This problem is pretty common and can be solved very easily using a FOR statement. In this example we will be searching a directory for every item stored inside. Each item will be added to the integer %%A. For more information do FOR /? inside a command window.
for %%a in ("Directory") DO (Action)
For copying files, we will use the copy command. Please keep note that we will be using parameter extensions to expand the %%A to have no extension using %%~na. More info here: Parameter Extensions
This script will copy & rename Doom.jpg to G:\Doom for each item in the directory.
Batch File:
for %%a in ("G:\Doom\*") do (copy "C:\Users\Dane\Pictures\Doom.jpg" "G:\Doom\%%~na.png")
Command Prompt:
for %a in ("G:\Doom\*") do (copy "C:\Users\Dane\Pictures\Doom.jpg" "G:\Doom\%~na.png")

Related

Exiftool - changing PENTAX related EXIF tags to Pentax [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed last year.
Improve this question
I just discovered that GIMP 2.10 removes JPG EXIF data because of the "PENTAX" in uppercase present in the EXIF data (the bug is described here and here).
Tried Exif Pilot freeware and found out the EXIF fields:
Make=PENTAX
Model=PENTAX K-x
Fixing them to "Pentax K-x" and "Pentax" solves the problem but requires me to do it manually one by one in Exif Pilot GUI.
Is there any way to do this as batch for a whole folder with JPG files? I tried to find some Exiftool parameters to replace "PENTAX" with "Pentax" but to keep the model information correctly but no success so I would appreciate help.
thanks
Using exiftool, you could use this command
exiftool -api "filter=s/PENTAX/Pentax/" -TagsFromFile # -Model -Make /path/to/files/
The -api Filter option will do a regex substitution changing PENTAX into Pentax. The -TagsFromFile option will copy the modified Model and Make tags back into the file. It will not affect any file that doesn't contain PENTAX in those two tags.
This command creates backup files. Add -overwrite_original to suppress the creation of backup files. Add -r to recurse into subdirectories.
Windows is lacking in having the generic command grep for this common task on many other systems. The jpeg files are binary but like a PDF the Meta data itself is held as plain text. Do check your text string is similar to below otherwise you will/may need to parse both PENTAX entries separately as single words.
So in this fixed case it it should be easy to use any binary file reader / writer and "Find aNd Replace" the text string. Just ensure it is byte for byte the same length.
Find =PENTAXPENTAX K-x
Replace =PentaxPentax K-x
DO NOT use Notepad and sadly the native cmd tool Debug.exe was removed long ago. However you might use inbuilt PowerShell of which lit is an advocate. :-)
You could use the well known exiftool but that is yet another exe to add to your dedicated file utilities collection.
Otherwise consider downloading a more universal small CMD batch file like dbenhams jrepl.bat which can be used for hundreds of other file type tasks.
jrepl PENTAXPENTAX PentaxPentax /M /f user-default-avatar.jpg /o -
So the code you need to consider is how you write a loop for doing all your files and thus I will suggest you use For /? and look at the options to add a folder of files something like For %F in (*.jpg) do jrepl ... However, as there are no error checks or backup, I suggest it be something like this
#echo off & Title Replacing PENTAX
set "Find=PENTAX"
set "Replace=Pentax"
for %%F in (*.jpg) do #(
echo replacing %find% in %%F
if not exist %%~nF.bak copy %%F /B %%~nF.bak /B >nul
#jrepl "%Find%" "%Replace%" /M /F %%F /o -
)

Copy files from a list.txt, output error log

I have read many posts covering copy and xcopy, but i am unable to get my command to work.
I aim is to create a batch file that will do the following;
Search a directory structure for a list of files 'names only' if found copy them to another directory. If not found create an error list.
The txt format of files I am looking for can be in any format however in testing i have a text file like this;
1603010853
1603020845
1603141400
1604061215
The files are .PDF or .TIF
The directory structure that I am searching is like this;
X:DEL>16>160314>1603141400.pdf
X:DEL>16>160301>1603010853.tif
I am struggling to get it to work as the list is not the full path.
for /f "tokens=*" %i in (File-list.txt) DO xcopy /S/E "c:Test\In%i" "c:out"
Thanks in advance
Fostersimported
Alrighty, if tool doesn't matter much, I'd suggest going with the PowerShell script attached to this SuperUser post. It seems to do everything you want (including logging errors). You'd need only copypasta that into a text file, name it accordingly, and go from there.

Search for specific directory names within subdirectories and copy files (Windows batch)

need some help with this one
I have a directory that contains subdirectories from various applications so let's say directory is c:\home and each application has a subdirectory called the application name so we will have
c:\home\app1
c:\home\app2
etc.
These applications write large log files and they then get recreated every hour but into a different directory, called according t date and time like dd/mm/yyyy/hr and this is created within the actual subdirectory and a log file with the exact same name will be within each directory for each app. so we will end up with this
c:\home\app1\1015201410\app1.log
c:\home\app1\1015201411\app1.log
c:\home\app1\1015201412\app1.log
c:\home\app2\1015201410\app2.log
c:\home\app2\1015201411\app2.log
c:\home\app2\1015201412\app2.log
I want to list through the directories every hour and collect the latest log from each application, in other words in this instance I want to collect the following 2 only as they are the latest (end time 12 shows it is the 12th hour)
c:\home\app1\1015201412\app1.log
c:\home\app4\1015201412\app2.log
Now getting the file one by one is easy enough but the script is going to become too long and needs to be edited on a regular base to allow for new applications added to the directories.
I am able to do the copying, formatting the time/date section etc. I just need to find a way to search through the home directories for all subdirectories containing the latest timedate and then copy a file from it elsewhere.
So I tried this. Note timedateformat has been predefined:
for /D %%d in (c:\home\*\%timedateformat%\*) do (
for %%f in (%%d\.log) do (
xcopy %%f C:\destination\
)
)
but this obviously does not like the * part and therefore I will get no result.
Please if anyone is able to assist, I would greatly appreciate.
for /d %%F in ("c:\home\*") do xcopy "%%F\%timedateformat%\*.log" "c:\destination\"

Why file cannot be found to copy

I am writing a batch script which will copy a file from a folder into the C:\ drive:
#ECHO ON
COPY C:\RANDOMFILES\Weekly Reprort_Hew*.xls C:\Weekly Reprort_Hew???????????.xls
The filename in the RANDOMFILES folder is: Weekly Reprort_Hew, 6-29-2014 10-30-00 PM-642.xls (The date and time and the number at the end will always change so I used the * in the filename being copied in the script)
When I run the batch script, I get the following message:
c:\RANDOMFILES>COPY C:\RANDOMFILES\Weekly Reprort_Hewlett*.xls C:\Weekly Reprort
_Hewlett???????????.xls
The system cannot find the file specified.
How can I fix the issue?
You need double quotes to handle spaces etc. Double check the spelling too.
#ECHO ON
COPY "C:\RANDOMFILES\Weekly Reprort_Hew*.xls" "C:\Weekly Reprort_Hew???????????.xls"
Don't know why it is not working - is it hidden? Maybe the spaces in the name?
The following will work though:
FOR %%I in (C:\RANDOMFILES\Weekly Reprort_Hew*.xls) DO COPY "%%I" C:\
The destination file name isn't necessary; if not otherwise specified, it will remain unchanged provided the destination is different. That may be why the plain COPY command isn't working.
Also:
"It is an not-so-well-known fact that the question mark wildcard will match exactly one character only when the wildcard does not appear at the end of a file name. " from http://www.thefriendlycoder.com/2011/11/24/batch-file-gotcha-question-mark-wildcard/

Windows batch file: rename files (possibly in multiple folders) based on input file (of target filenames)

I am a Batch-newbie, so please accept my apologies and Thanks in advance !
This "tool" is to automate the slimming down of Windows (XP) by disabling certain system driver, DLL and EXE files. Instead of outright deletion, I wish to rename-in-place, thus "removing" them from the OS, but not losing sight of where they belong (should any need to be "restored"). Renaming is accomplished by appending a new suffix to the existing filename (eg: "wdmaud.drv.group_1") The renaming suffix should be another input variable.
The target-list is approx. 1100 files long (divided into various groups/phases), so manual renaming is out of the question. Each group will be processed in a separate run of the batch file, varying the target-list input file for each execution.
Target-list is plain text file, one filename per line (no other data in the files). Number of entries per group varies. Target list will look like this:
-- example start --
netapi.dll
netcfgx.dll
netdde.exe
netevent.dll
neth.dll
netid.dll
netrap.dll
nic1394.sys
-- example end --
Filenames may be in UPPER, lower, or MiXeD case. The files may be present in more than one folder in the C:\Windows hierarchy - or may not be present at all. If a file is not found anywhere in the system, it's name should be written to a text file, one-entry-per-line.
The specific folders of interest are:
C:\WINDOWS\
C:\WINDOWS\system\
C:\WINDOWS\system32\
C:\WINDOWS\system32\dllcache
C:\WINDOWS\system32\drivers
The renaming will be done by connecting the target OS drive to another XP computer, so locked system files should not be a problem.
Any help you can offer will be greatly appreciated.
a double FOR loop may help you.. this is a very simple example, just to get you started
for /f "tokens=*" %%f in (%targetlist%) do (
for /f "tokens=*" %%d in (%dirlist%) do (
if exist "%%d\%%f" echo %%f found in %%d
)
)
see HELP FOR.

Resources