Copy a list of files with the same names but different extensions to a new directory

Slab

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.

Gerhard

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

list files with different extensions from a directory

From Dev

list files with different extensions from a directory

From Dev

How can I copy multiple files in the same directory with different names but same extension in bash?

From Dev

Get the list of files from document directory contains same name but with different extensions.

From Dev

Copy *changed/new files only* to a DIFFERENT directory?

From Dev

rsync: copy updated/new files to DIFFERENT directory

From Dev

copy files from different locations and with different names into one target directory

From Dev

copy files from different locations and with different names into one target directory

From Dev

Recursively move files with different names and different extensions

From Dev

Use data from different files with same names but different extensions to get the line numbers

From Dev

gzip several files in different directories and copy to new directory

From Dev

Copy files in folders with different names

From Dev

Linux - How to copy a list of files with special characters to new directory

From Dev

Get a list of tuples containing files with the same names but different endings

From Dev

How to copy multiple files but keep their extensions the same?

From Dev

List all unique extensions for files contained in a directory

From Dev

How to detect files with the same name but different extensions?

From Dev

How to detect files with the same name but different extensions?

From Dev

Finding and copying files with same name but different extensions

From Dev

zip multiple files with the same name but different extensions

From Dev

Copy a directory and all its files from the master branch into a new branch with a different directory structure

From Dev

Copy files of same name into same directory

From Dev

Need to copy files to existing directory and remove files already there with the same name but different extension

From Java

bash: use list of file names to concatenate matching files across directories and save all files in new directory

From Dev

Global alias for all files in a directory, by their file names (extensions, if available will be omitted)

From Dev

How do I copy files recursively through a directory tree while appending parent folder names to the new files? Batch or VBScript

From Dev

How do I copy files recursively through a directory tree while appending parent folder names to the new files? Batch or VBScript

From Dev

How to copy all files in same directory as gulpfile?

From Dev

Copy files to same directory with another name

Related Related

  1. 1

    list files with different extensions from a directory

  2. 2

    list files with different extensions from a directory

  3. 3

    How can I copy multiple files in the same directory with different names but same extension in bash?

  4. 4

    Get the list of files from document directory contains same name but with different extensions.

  5. 5

    Copy *changed/new files only* to a DIFFERENT directory?

  6. 6

    rsync: copy updated/new files to DIFFERENT directory

  7. 7

    copy files from different locations and with different names into one target directory

  8. 8

    copy files from different locations and with different names into one target directory

  9. 9

    Recursively move files with different names and different extensions

  10. 10

    Use data from different files with same names but different extensions to get the line numbers

  11. 11

    gzip several files in different directories and copy to new directory

  12. 12

    Copy files in folders with different names

  13. 13

    Linux - How to copy a list of files with special characters to new directory

  14. 14

    Get a list of tuples containing files with the same names but different endings

  15. 15

    How to copy multiple files but keep their extensions the same?

  16. 16

    List all unique extensions for files contained in a directory

  17. 17

    How to detect files with the same name but different extensions?

  18. 18

    How to detect files with the same name but different extensions?

  19. 19

    Finding and copying files with same name but different extensions

  20. 20

    zip multiple files with the same name but different extensions

  21. 21

    Copy a directory and all its files from the master branch into a new branch with a different directory structure

  22. 22

    Copy files of same name into same directory

  23. 23

    Need to copy files to existing directory and remove files already there with the same name but different extension

  24. 24

    bash: use list of file names to concatenate matching files across directories and save all files in new directory

  25. 25

    Global alias for all files in a directory, by their file names (extensions, if available will be omitted)

  26. 26

    How do I copy files recursively through a directory tree while appending parent folder names to the new files? Batch or VBScript

  27. 27

    How do I copy files recursively through a directory tree while appending parent folder names to the new files? Batch or VBScript

  28. 28

    How to copy all files in same directory as gulpfile?

  29. 29

    Copy files to same directory with another name

HotTag

Archive