2

I have a bin folder containing dll files built both in debug and release:

myFirstFile.dll
myFirstFiled.dll
mySecondFile.dll
mySecondFiled.dll
...

File names are different from each other, but the rule is that the dlls built in Debug mode ends with 'd'. I can't find a way in a .bat script to copy these files to two different folders named Debug and Release so that the dlls ending with 'd' are copied in the Debug folder and all the others in the Release folder.

John C
  • 4,276
  • 2
  • 17
  • 28
ABCplus
  • 3,981
  • 3
  • 27
  • 43
  • So basically you have to check if your filename contains `d.dll`? Maybe this can be handy: http://stackoverflow.com/questions/7005951/batch-file-find-if-substring-is-in-string-not-in-a-file. Ofcourse it has one flaw, if your (release) dll filename ends with a `d` – Perneel Jul 02 '14 at 14:23
  • Your link is about finding a substring in a string given as parameter to batch. Instead I need to iterate over a file list. – ABCplus Jul 02 '14 at 14:26
  • use for loop to iterate through the files, see the answer of konsolebox :) – Perneel Jul 02 '14 at 14:31

2 Answers2

2
mkdir Debug
mkdir Release
for %a in (*.dll) do if exist %~nad.dll move %~nad.dll Debug
move *.dll Release
konsolebox
  • 72,135
  • 12
  • 99
  • 105
  • I get the error: _The following usage of the path operator in batch-parameter substitution is invalid: %~nad.dll Debug For valid formats type CALL /? or FOR /? ☻ was unexpected at this time._ – ABCplus Jul 02 '14 at 14:33
  • 1
    @ABCplus Are you running it under a cmd script / batch file? If so your variables need to be `%%a` and `%%~na` respectively. – konsolebox Jul 02 '14 at 14:34
  • Yes, it was batch file. Works as expected now! Thank you – ABCplus Jul 02 '14 at 14:38
2

You can use in-place variable editing to check for the filename ending, as in the following example:

setlocal enabledelayedexpansion
for %%F in (*.dll) do (
    set plainname=%%~nF
    if "!plainname:~-1!"=="d" (
        move %%F DEBUG
    ) else (
        move %%F RELEASE
    )
)
endlocal
ocho88
  • 125
  • 1
  • 8