Question

Okay this is and isn't programming related I guess...

I've got a whole bunch of little useful console utilities scattered across a suite of projects that I wrote and I want to dump them all to a single directory to make using them simpler. The only issue is that I have them all compiled in both Debug and Release mode.

Given that I only want the release mode versions in my utilities directory, what switch would allow me to specify that I want all executables from my tree structure but only from within Release folders:

Example:

Projects\   
  Project1\
    Bin\
      Debug\
        Project1.exe
      Release\
        Project1.exe   
  Project2\

etc etc...

To

Utilities\
  Project1.exe
  Project2.exe
  Project3.exe
  Project4.exe
  ...

etc etc...

I figured this would be a cinch with XCopy - but it doesn't seem to allow me to exclude the Debug directories - or rather - only include items in my Release directories.

Any ideas?

Was it helpful?

Solution

You can restrict it to only release executables with the following. However, I do not believe the other requirement of flattening is possible using xcopy alone. To do the restriction:

First create a file such as exclude.txt and put this inside:

\Debug\

Then use the following command:

xcopy /e /EXCLUDE:exclude.txt *.exe C:\target

You can, however, accomplish what you want using xxcopy (free for non-commercial use). Read technical bulletin #16 for an explanation of the flattening features.

If the claim in that technical bulletin is correct, then it confirms that flattening cannot be accomplished with xcopy alone.

The following command will do exactly what you want using xxcopy:

xxcopy /sgfo /X:*\Debug\* .\Projects\*.exe  .\Utilities

I recommend reading the technical bulletin, however, as it gives more sophisticated options for the flattening. I chose one of the most basic above.

OTHER TIPS

Sorry, I haven't tried it yet, but shouldn't you be using:

xcopy release*.exe d:\destination /s

I am currently on my Mac so, I cant really check to be for sure.

This might not help you with assembling them all in one place now, but going forward have you considered adding a post-build event to the projects in Visual Studio (I'm assuming you are using it based on the directory names)

xcopy /Y /I /E "$(TargetDir)\$(TargetFileName)" "c:\somedirectory\$(TargetFileName)"

Ok, this is probably not going to work for you since you seem to be on a windows machine.
Here goes anyway, for the logic.

# From the base directory
mkdir Utilities
find . -type f | grep -w Release > utils.txt
for f in $(<utils.txt); do cp $f Utilities/; done

You can combine the find and cp lines into one, I split them for readability.

To do this on a windows machine you'll need Cygwin or some such Unix Utilities handy.
Maybe there are tools in the Windows shell to do this...

This may help get you started:

C:\>for %i in (*) do  dir "%~dpi\*.exe"

Used in the dir command as a modifier to i, ~dp uses the drive and path of everything found in (*). If I run the above in a folder that has several subfolders containing executables, I get a dir list of all of the executables in each folder.

You should be able to modify that to add '\bin\release\' following the ~dpi portion and change dir to xcopy. A little experimentation should make it pretty easy.

To use the for statement above in a batch file, change '%' to '%%' in both places.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top