Bat file to copy specific files to common folder?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jeff p
Posts: 42
Joined: 28 Jul 2009 10:21

Bat file to copy specific files to common folder?

#1 Post by jeff p » 20 Jul 2012 11:05

Hello,

I have a folder (D:\Images), which contains about 50 folders. Within these 50 folders are a sequence of 237 .tga images
The file names of each sequence are unique for each folder.. ie:

ImageA0001.tga... through ImageA0237.tga,
ImageDF0001.tga... through ImageDF0237.tga,
ImageB0001.tga... through ImageB0237.tga,

etc

I would like to copy two images from each sequence folder and paste these into 1 common folder.(D:\Images\Common)
the 2 images I'd like to copy are: *0001.tga, and *0007.tga

Any ideas how to achieve this?

Thanks for any help

Jeff

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Bat file to copy specific files to common folder?

#2 Post by Squashman » 20 Jul 2012 11:18

This should work. Untested!

Code: Select all

@echo off

pushd D:\Images

FOR /F "delims=" %%G in ('dir /a-d /b /s *0001.tga *0007.tga' ^|findstr /I /V /B /C:"D:\Images\Common\"') do (
   copy "%%~G" "D:\Images\common"
)

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Bat file to copy specific files to common folder?

#3 Post by foxidrive » 20 Jul 2012 20:25

That can copy some other files if the short filename matches the filespec as well.



This change might fix that possible issue:


Code: Select all

@echo off
pushd D:\Images
FOR /F "delims=" %%G in ('dir /a-d /b /s *.tga ^|findstr /i "0001.tga 0007.tga"^|findstr /I /V /B /C:"D:\Images\Common\"') do (
   copy "%%G" "D:\Images\common"
)


Edit: added missing ^ character
Last edited by foxidrive on 20 Jul 2012 23:01, edited 1 time in total.

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Bat file to copy specific files to common folder?

#4 Post by Squashman » 20 Jul 2012 21:36

foxidrive wrote:That can copy some other files if the short filename matches the filespec as well.



This change might fix that possible issue:


Code: Select all

@echo off
pushd D:\Images
FOR /F "delims=" %%G in ('dir /a-d /b /s *.tga ^|findstr /i "0001.tga 0007.tga"|findstr /I /V /B /C:"D:\Images\Common\"') do (
   copy "%%G" "D:\Images\common"
)

Thanks Foxidrive

jeff p
Posts: 42
Joined: 28 Jul 2009 10:21

Re: Bat file to copy specific files to common folder?

#5 Post by jeff p » 21 Jul 2012 02:45

Awesome..works perfectly.!

Couldn't get the first code to work initially, but the one within Foxidrives' thread worked!

Thanks for all the help on this!

Very much appreciated.

Jeff

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Bat file to copy specific files to common folder?

#6 Post by Squashman » 21 Jul 2012 08:24

jeff p wrote:Awesome..works perfectly.!

Couldn't get the first code to work initially, but the one within Foxidrives' thread worked!

Thanks for all the help on this!

Very much appreciated.

Jeff

Really not much of a difference with our code. He just adds an extra PIPE to another FINDSTR. Technically both should work.

Post Reply