With my DSLR camera I have JPGs stored on one SD card and RAW files on the second SD card. Currently I am copying all the .JPG files from one SD card to a folder on the PC, sorting through them, and deleting the unwanted ones.
The second SD card full of RAW files have the same file names as the JPGs but with the extension .NEF.
I want to create a list of the remaining JPG files on the PC, and then only copy the matching .NEF files over to the PC.
I want to create a batch file to automate this.
I can create a simple list of files in a directory by using
dir /b /a-d > filelist.txt
But this creates a list of filenames including the .JPG extensions, and presumably I need just the filename without the extension, so I can then use the list to copy over the matching .NEF files from the other SD card.
I am trying to use the following to then copy the files, but I can't get it working properly.
@echo off
set src_folder=J:\DCIM\101D7100
set dst_folder=D:\Photos\1\RAW
for /f "tokens=*" %%i in (filelist.txt) DO (
xcopy /S/E "%src_folder%\%%i" "%dst_folder%"
)
Thanks for any advice.
By using %%~ni
instead, you use only the name excluding the extension. Assuming you want all the .NEF
files for the .JPG
files already in a dir, instead of processing it to a file, then reading from file, simply process it directly. As an example, let's say the directory you used to do dir /b /a-d > filelist.txt
is D:\JPEGs
, then simply do:
This simply takes the name of the JPG file and strips the extension, then we copy the name and add .NEF extension.
@echo off
set "src_folder=J:\DCIM\101D7100"
set "dst_folder=D:\Photos\1\RAW"
for %%i in ("D:\JPEGS\*.jpg") do (
xcopy /S/E "%src_folder%\%%~ni.NEF" "%dst_folder%"
)
Additionally, always set a variable, using double quotes before variable name and after the path, just to ensure there are no hidden whitespace in your typing.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments