将过滤器中的所有.cpp和.h移动到另一个项目,并纠正它们的文件夹位置

时间:2021-11-18 22:50:06

Here is filter of my project in Visual Studio shown in Solution Explorer :-

这是我在Visual Studio中的项目过滤器,显示在解决方案资源管理器:-

ProjectName1
== References, External Dependencies, Header Files, Resource Files
== Source Files
==== myFilter01
------ K.h               (system folder = `D:\ProjectName1\K.h`)
------ K.cpp             (system folder = `D:\ProjectName1\K.cpp`)   
==== myFilter02                                                 
====== subFilter2_1                                              
--------- B.h            (system folder = `D:\ProjectName1\B.h`)
--------- B.cpp          (system folder = `D:\ProjectName1\B.cpp`)   
========= subFilter2_2                                           
----------- C.h          (system folder = `D:\ProjectName1\C.h`)   
----------- C.cpp        (system folder = `D:\ProjectName1\C.cpp`)   
ProjectName2                                                   
== ... (some existing filter/files)    

(In real case, all filters contains a lot of sub-sub-filter and files.)

(在实际情况下,所有过滤器都包含许多子过滤器和文件。)

Question

How to :

如何:

  • move all .h and .cpp files (B and C) inside myFilter02 to ProjectName2's folder (e.g. D:\ProjectName2)
  • 将myFilter02中的所有.h和.cpp文件(B和C)移到ProjectName2的文件夹中(例如D:\ProjectName2)
  • don't change appearance of the filter (e.g. C must be still in subFilter2_1\subFilter2_2)
  • 不要改变过滤器的外观(例如,C必须仍然在subFilter2_1\subFilter2_2中)
  • and do it in a few clicks (i.e. not depend on amount of files/sub-filters) i.e. O(1)
  • 只需点击几下鼠标(即不依赖于文件/子过滤器的数量),也就是O(1)

Here is the expected result :-

这是预期的结果:

ProjectName1
== References, External Dependencies, Header Files, Resource Files
== Source Files
==== myFilter01
------ K.h               (system folder = `D:\ProjectName1\K.h` )
------ K.cpp             (system folder = `D:\ProjectName1\K.cpp` )   
==== myFilter02 
ProjectName2
== ... (some existing filter/files)       
== subFilter2_1                                                             
----- B.h                (system folder = `D:\ProjectName2\B.h` )
----- B.cpp              (system folder = `D:\ProjectName2\B.cpp` )
===== subFilter2_2                                             
------- C.h              (system folder = `D:\ProjectName2\C.h` )
------- C.cpp            (system folder = `D:\ProjectName2\C.cpp` )

It can be done manually for each sub-sub-sub-filter + add existing files, but it is very tedious.

每个子子子过滤器+添加现有文件都可以手动完成,但是非常繁琐。

I tried to right click the filter/files, but didn't found such feature.
I currently don't use any Microsoft's source control / repository (just in case it is related).

我试着右键点击过滤器/文件,但是没有找到这样的功能。我目前不使用任何微软的源代码控制/存储库(只是在相关的情况下)。

Note: The normal drag & drop on filters don't move the files to another project's folder.
It just makes the moved files to be a shortcut of the original location (D:\ProjectName1\).

注意:过滤器上的常规拖放不会将文件移动到另一个项目的文件夹。它只是使移动的文件成为原始位置的快捷方式(D:\ProjectName1\)。

Hotkey? Plugin? Script?
Do I really have to create a program to do this specific thing?

热键吗?插件吗?脚本?我真的需要创建一个程序来做这个特定的事情吗?

A few days after asking, I have coded it with c++ using RapidXML ~ 500-1000 lines.
I have to edit .vcxproj.filters and .vcxproj of both projects, and move some system files.
I still find no answer about the question, though.

问了几天之后,我用c++用RapidXML ~ 500-1000行编写了它。我必须编辑。vcxproj。两个项目的过滤器和.vcxproj,并移动一些系统文件。不过,我仍然没有找到关于这个问题的答案。

Edit

(After receive advise from Hans Passant and Prab, thank!)
I want to use filter rather than folder for these reasons :-

(收到汉斯·帕桑和普拉博的建议后,谢谢!)由于这些原因,我想使用过滤器而不是文件夹:-

  • Source control is easier, because all source files are in a same directory.
  • 源代码控制比较容易,因为所有源文件都在同一个目录中。
  • In Visual Studio, I can move files around different filters a little easier than around folders.
  • 在Visual Studio中,我可以在不同的过滤器中移动文件,这比在文件夹中移动要容易一些。
  • With Filter, I don't have to lengthen #include "../myFilter01/K.h" or add additional include directories for each folder. I can simple #include "K.h".
  • 使用过滤器,我不需要延长#include ../myFilter01/K。或为每个文件夹添加额外的包含目录。我可以简单地写上“K.h”。
  • If I change the place where a file resides in a filter, I don't have to refactor it.
    In case of changing folder, I have to refactor code.
  • 如果我改变一个文件在过滤器中的位置,我不需要重构它。如果要更改文件夹,我必须重构代码。
  • I can use very strange character e.g. =◆██myFilter01██◆= for filters but not folder. It is my taste.
  • 我可以用很奇怪的性格如=◆██myFilter01██◆=过滤器而不是文件夹。这是我的口味。

I don't want to

我不想

  • Use folder instead of filter : Beside difficulty of recreate many folders and move my .cpp/.h files manually, I will suffer the above disadvantages.
  • 使用文件夹而不是过滤器:除了重新创建多个文件夹和移动我的。cpp/。h文件手动,我将遭受上述缺点。
  • Use folder with same structure as filter : I have to keep it in sync together manually (all the time - tedious). I will still get some the above disadvantages.
  • 使用与过滤器相同结构的文件夹:我必须手动同步它(所有时间都很乏味)。我还是会得到上面提到的一些缺点。

In summary, using folder instead of filter causes me more new trouble than it solves.

总之,用文件夹代替过滤器给我带来的麻烦比它解决的麻烦要多。

1 个解决方案

#1


0  

It's not one click solution but it could be done faster then manual.

这不是一个点击解决方案,但它可以比手动更快地完成。

  1. Find out what file need to be copied. To do that move filters from one project to another. Then switch to directory view (show all files) for first project and copy but not past files with small red indicator (files that are not included in the project). Now get back to filter view for both project and move back filters to first project. After that switch both projects to directory view and do pass on second project.

    找出需要复制的文件。为此,将过滤器从一个项目移动到另一个项目。然后切换到目录视图(显示第一个项目的所有文件),用红色小指示符复制但不复制过去的文件(项目中不包含的文件)。现在返回到两个项目的filter视图,并返回到first项目。然后将两个项目切换到目录视图,并传递第二个项目。

  2. Now we need to create correct filters. Move files from source and header filter to another filters in second project. Unload both projects. Open first and second project .filters files copy from first file to second all filter tags except "Source Files", "Header Files", "Resource Files". Next from second file remove all tags started with source or header. Now from second ItemGroup copy whole content and pass it to second file second ItemGroup. Save second file.

    现在我们需要创建正确的过滤器。将文件从源文件和头过滤器移到第二个项目中的另一个过滤器。卸下两个项目。打开第一个和第二个项目。过滤器文件从第一个文件复制到第二个所有过滤器标签,除了“源文件”、“头文件”、“资源文件”。从第二个文件中删除所有从源或头开始的标记。现在从第二个项目组复制整个内容并传递给第二个文件第二个项目组。保存第二个文件。

  3. In this point you should have copy of first project filter tree without unnecessary files now just move what you want to correct places.

    在这一点上,您应该拥有第一个项目过滤树的副本,而没有不必要的文件,现在只需移动您想要纠正的地方。

It is helpful to create single tree in first project.

在第一个项目中创建单个树是很有帮助的。

#1


0  

It's not one click solution but it could be done faster then manual.

这不是一个点击解决方案,但它可以比手动更快地完成。

  1. Find out what file need to be copied. To do that move filters from one project to another. Then switch to directory view (show all files) for first project and copy but not past files with small red indicator (files that are not included in the project). Now get back to filter view for both project and move back filters to first project. After that switch both projects to directory view and do pass on second project.

    找出需要复制的文件。为此,将过滤器从一个项目移动到另一个项目。然后切换到目录视图(显示第一个项目的所有文件),用红色小指示符复制但不复制过去的文件(项目中不包含的文件)。现在返回到两个项目的filter视图,并返回到first项目。然后将两个项目切换到目录视图,并传递第二个项目。

  2. Now we need to create correct filters. Move files from source and header filter to another filters in second project. Unload both projects. Open first and second project .filters files copy from first file to second all filter tags except "Source Files", "Header Files", "Resource Files". Next from second file remove all tags started with source or header. Now from second ItemGroup copy whole content and pass it to second file second ItemGroup. Save second file.

    现在我们需要创建正确的过滤器。将文件从源文件和头过滤器移到第二个项目中的另一个过滤器。卸下两个项目。打开第一个和第二个项目。过滤器文件从第一个文件复制到第二个所有过滤器标签,除了“源文件”、“头文件”、“资源文件”。从第二个文件中删除所有从源或头开始的标记。现在从第二个项目组复制整个内容并传递给第二个文件第二个项目组。保存第二个文件。

  3. In this point you should have copy of first project filter tree without unnecessary files now just move what you want to correct places.

    在这一点上,您应该拥有第一个项目过滤树的副本,而没有不必要的文件,现在只需移动您想要纠正的地方。

It is helpful to create single tree in first project.

在第一个项目中创建单个树是很有帮助的。