Conditional copy

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Manu310
Posts: 2
Joined: 20 Mar 2017 09:38

Conditional copy

#1 Post by Manu310 » 20 Mar 2017 10:12

Hi all ! :)
Quite new to batch (or at least to do more than call scripts and change
directory) here...
For my project, I'm trying to copy all dll from a directory in delivery
directory... I can already to that "brainless" with :

Code: Select all

FOR /R %srcDir% %%f IN (*.dll) DO COPY %%f %destDir%

But the goal has changed since. Indeed, I need to copy dll but not all of them
(I want to copy release dll but not debug dll... for a lib like Qt for instance)
So far here is the sort of terrible thing I tried to write:

Code: Select all

FOR /R %srcDir% %%f IN (*.dll) DO (
 SET temp = %%f
 SET temp = !temp:d4.dll=!
 IF %%f==!temp! COPY %%f %destDir%
)

Could you help me get this working ? :) (Actually, I'm kind of lost with
variables in batch, between var, %var%, %%var, !var!...)
Manu

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Conditional copy

#2 Post by penpen » 20 Mar 2017 10:54

You could put the release and debug dlls into different locations:

Code: Select all

FOR /R "%srcDir%/debug" %%f IN (*.dll) DO COPY %%f %destDir%
FOR /R "%srcDir%/release" %%f IN (*.dll) DO COPY %%f %destDir%


penpen

Manu310
Posts: 2
Joined: 20 Mar 2017 09:38

Re: Conditional copy

#3 Post by Manu310 » 21 Mar 2017 02:18

Thanks for your answer !
That would be the most relevant way to do it, but I'm working on an existing architecture and I can't simply move every files as I want with no consequences ^^

I actually managed to make it work, and learnt from my mistake: no whitespaces around the attribution = !
So I came with :

Code: Select all

setlocal enabledelayedexpansion
FOR /R %srcDir% %%f IN (*.dll) DO (
    SET t=%%f
    IF %%f==!t:d4.dll=! COPY %%f %destDir%
)


Now, I need to do the same kind of verification with scripts using xcopy and robocopy ^^

Post Reply