如何从众多版本目录复制到单个文件夹

时间:2022-03-20 07:09:04

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.

我有一大堆有用的控制台实用工具分散在我编写的一系列项目中,我想将它们全部转储到一个目录中,以便更简单地使用它们。唯一的问题是我在Debug和Release模式下都编译了它们。

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:

鉴于我只想在我的实用程序目录中发布模式版本,什么开关允许我指定我想要来自我的树结构的所有可执行文件,但只能从Release文件夹中:

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.

我认为这对XCopy来说很简单 - 但它似乎不允许我排除Debug目录 - 或者更确切地说 - 只包含我的Release目录中的项目。

Any ideas?

5 个解决方案

#1


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:

您可以将其限制为仅发布具有以下内容的可执行文件。但是,我不相信单独使用xcopy可以实现扁平化的其他要求。要做限制:

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

首先创建一个诸如exclude.txt之类的文件并将其放入:

\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.

但是,您可以使用xxcopy完成您想要的操作(免费用于非商业用途)。阅读技术公告#16,了解扁平化功能的说明。

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

如果该技术公告中的声明是正确的,那么它确认单独使用xcopy无法实现展平。

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

以下命令将使用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.

不过,我建议阅读技术公告,因为它为扁平化提供了更复杂的选项。我选择了上面最基本的一个。

#2


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

对不起,我还没有尝试过,但是你不应该使用它:

xcopy release*.exe d:\destination /s

xcopy release * .exe d:\ destination / s

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

我目前在我的Mac上,所以我真的不能确定。

#3


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)

这可能无法帮助您将它们全部集中在一个地方,但是您可以考虑在Visual Studio中为项目添加一个构建后事件(我假设您正在根据目录名称使用它)

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

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

#4


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.

好吧,这可能不适合你,因为你似乎在Windows机器上。无论如何,这是为了逻辑。

# 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.

您可以将find和cp行合并为一个,我将它们分开以便于阅读。

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...

要在Windows机器上执行此操作,您需要Cygwin或一些此类Unix Utilities。也许Windows shell中有工具可以做到这一点......

#5


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.

在dir命令中用作i的修饰符,~dp使用(*)中找到的所有内容的驱动器和路径。如果我在包含多个包含可执行文件的子文件夹的文件夹中运行上述内容,我会得到每个文件夹中所有可执行文件的目录列表。

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.

您应该能够修改它以在~dpi部分之后添加'\ bin \ release \'并将dir更改为xcopy。一点实验应该让它变得非常简单。

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

要在批处理文件中使用上述for语句,请在两个位置将'%'更改为'%%'。

#1


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:

您可以将其限制为仅发布具有以下内容的可执行文件。但是,我不相信单独使用xcopy可以实现扁平化的其他要求。要做限制:

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

首先创建一个诸如exclude.txt之类的文件并将其放入:

\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.

但是,您可以使用xxcopy完成您想要的操作(免费用于非商业用途)。阅读技术公告#16,了解扁平化功能的说明。

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

如果该技术公告中的声明是正确的,那么它确认单独使用xcopy无法实现展平。

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

以下命令将使用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.

不过,我建议阅读技术公告,因为它为扁平化提供了更复杂的选项。我选择了上面最基本的一个。

#2


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

对不起,我还没有尝试过,但是你不应该使用它:

xcopy release*.exe d:\destination /s

xcopy release * .exe d:\ destination / s

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

我目前在我的Mac上,所以我真的不能确定。

#3


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)

这可能无法帮助您将它们全部集中在一个地方,但是您可以考虑在Visual Studio中为项目添加一个构建后事件(我假设您正在根据目录名称使用它)

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

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

#4


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.

好吧,这可能不适合你,因为你似乎在Windows机器上。无论如何,这是为了逻辑。

# 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.

您可以将find和cp行合并为一个,我将它们分开以便于阅读。

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...

要在Windows机器上执行此操作,您需要Cygwin或一些此类Unix Utilities。也许Windows shell中有工具可以做到这一点......

#5


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.

在dir命令中用作i的修饰符,~dp使用(*)中找到的所有内容的驱动器和路径。如果我在包含多个包含可执行文件的子文件夹的文件夹中运行上述内容,我会得到每个文件夹中所有可执行文件的目录列表。

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.

您应该能够修改它以在~dpi部分之后添加'\ bin \ release \'并将dir更改为xcopy。一点实验应该让它变得非常简单。

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

要在批处理文件中使用上述for语句,请在两个位置将'%'更改为'%%'。