help writing a DOS batch file

Hi,

I'm having some trouble writing a DOS batch file and I hope one of you can give me a hand.

I have this list of folders, of which some of them have a Builds\bin\ subfolder with two DLLs in it (and possible other files), one called <filename>.dll and one <filename>D.dll (a debug version of the DLL). (Notice that the names bellow are not the actual names ;) ).

+ Common
+ Project1
+ Builds
+ Bin
- library1.dll
- library1D.dll
- somethingelse.ext
+ Project2
+ Builds
+ Bin
- library2.dll
- library2D.dll
+ Misc
+ Project3
+ Builds
+ Bin
- library3.dll
- library3D.dll
- somethingelse.ext

What I want to do is copying all the release version of the DLLs (<filename>.dll) to one folder and the debug version (<filename>D.dll> to another folder.

What I managed to do is copying both files to the folder for the release version, and then moving from this folder the files ending in D.DLL:

FOR /D %%i in (.\*) DO (
COPY %%i\Builds\Bin\*.DLL D:\Projects\Release\
)

FOR %%i in (D:\Projects\Release\*D.DLL) DO (
MOVE %%i D:\Projects\Debug\
)

(Again notice that are not the actual paths I'm using, but that's totally irelevant.)

However, this approach means 2 operation: one copy and one move. And the thing is I have tens of such projects from which I have to copy the DLLs and I'm not happy at all with this 2-steps copying.

So, what I'm looking for is something like this (in pseudo-code)

FOR /D %%i in (.\*) DO (
IF file-ends-in-D.dll (
COPY file D:\Projects\Debug\
)
ELSE (
COPY file D:\Projects\Release\
)
)

Does anyone of you know how to do that?

Thank you,
Cilu
[1941 byte] By [cilu] at [2007-11-19 22:19:31]
# 1 Re: help writing a DOS batch file
Cilu... This belongs to the scripting forum... And not Chit-Chat. :D
Siddhartha at 2007-11-9 12:59:12 >
# 2 Re: help writing a DOS batch file
Cilu... This belongs to the scripting forum... And not Chit-Chat. :D
Please stay on-topic. :D

Well, don't worry, I'm satisfied with this forum (for the moment). ;)
cilu at 2007-11-9 13:00:11 >
# 3 Re: help writing a DOS batch file
Well, don't worry, I'm satisfied with this forum (for the moment). This should not be a question of the OP's satisfaction - right?

Reasons why technical questions should not be allowed to stay in Chit-Chat follow:
(I am preaching to the choir... :D )

Reason # 1: They don't add to the post count.
Reason # 2: They can't be rated (for those who believe in ratings).

;)

Please stay on-topic. We are on topic... :D

Chit-chatting... :D
Siddhartha at 2007-11-9 13:01:18 >
# 4 Re: help writing a DOS batch file
Why waste 2 days of time finding way in scripting ??? you can write a simple C program which can tell you if the file has D in the end or not, and that will not take too must time to develop...so why script ? :confused:
Krishnaa at 2007-11-9 13:02:12 >
# 5 Re: help writing a DOS batch file
I would also write something like this in C or VB(seems easier to me).
Shuja Ali at 2007-11-9 13:03:19 >
# 6 Re: help writing a DOS batch file
Why waste 2 days of time finding way in scripting ??? you can write a simple C program which can tell you if the file has D in the end or not, and that will not take too must time to develop...so why script ? :confused:
Well, of course I can write a C++ program to do that with 20 lines of code... But I want to do with a script, if possible, whether it takes it days to figure it out. In the meanwhile I could learn something new. I already learned something about batch files... ;)
cilu at 2007-11-9 13:04:18 >
# 7 Re: help writing a DOS batch file
Good luck then...let us know if you find anything on that, that might save my 2 days sometimes. :p
Krishnaa at 2007-11-9 13:05:21 >
# 8 Re: help writing a DOS batch file
Good luck then...
LOL, very well said. :D

Even otherwise, a thread started in the wrong forum needs an extra-ordinary amount of luck to attract the right talent, or the right solution... Some OPs don't know this. :D ;) :p
Siddhartha at 2007-11-9 13:06:26 >
# 9 Re: help writing a DOS batch file
I have to ask again to stay on-topic. ;)
cilu at 2007-11-9 13:07:24 >
# 10 Re: help writing a DOS batch file
You're not concerned with postcount or reputations points, but posters who would answer your query are! Yes I am.

Anyways, who placed those files in such manner?

If it is one time copy-paste-move operation, why dont you do it yourself? Search the files, cut/copy paste them.

If the 'Bin' directory is filled by some project's output, change the Linker settings, or put 'move' or 'copy' command in Post build Setup.

Yes, I agree you are curious to know if it is possible. So, I've a suggestion for you:

Develop a Command Shell that can understand complex IF ELSE statements, including RIGHT(str,1)=='D'

Good luck!
Ajay Vijay at 2007-11-9 13:08:24 >
# 11 Re: help writing a DOS batch file
Batch files can only do very basic things without external programs...
That's why, you'll have to use an external program such as find.exe.
So, I think that using find.exe, which is part of MS-DOS utilities, I don't "cheat".

@echo off
rem treat_file.bat
echo %1 | find /I "D.DLL" > nul
if errorlevel 1 goto not_debug
echo Debug %1
goto end
:not_debug
echo Not debug %1
:end

@echo off
for %%x in (*.cpp) do call treat %%x

Extreme slowness is guaranteed. ;)
cilu: I hope you will not use that in real life.
SuperKoko at 2007-11-9 13:09:19 >
# 12 Re: help writing a DOS batch file
You're not concerned with postcount or reputations points, but posters who would answer your query are! Yes I am.
Then why did you bother answering me?

If it is one time copy-paste-move operation, why dont you do it yourself?
Well, that's what I used to do. Now, I have 30 such projects and in the future it may get up to 100. It would take me ages to do that manually. ;)

I hope you will not use that in real life.
Well, I'm planning to write a C++ application for that, but I did not yet decided whether I should use it from a batch file (something like Ajay suggested) and that can be reused for other purposes, or rather write some issue-oriented solution. Well, probably planning it will take more than coding... :D
cilu at 2007-11-9 13:10:28 >
# 13 Re: help writing a DOS batch file
Then why did you bother answering me?
You ought to be thankful, dude... :rolleyes:

His post is one of those that go towards making you extra-lucky.
Siddhartha at 2007-11-9 13:11:23 >