PowerShell:删除以前文件夹中已经存在的文件夹

发布于 2025-02-14 02:16:36 字数 1087 浏览 0 评论 0原文

假设我有一个文件夹,其中包含许多带有mainids和subids的子文件夹中的文件夹:

$path = 'C:\Users\user\main folder\folder'

例如,

$IDs = 'C:\Users\user\main folder\folder\mainID'
$SubIDs = 'C:\Users\user\main folder\folder\mainID\subID'

我还拥有另一个文件夹,它包含一个先前保存在另一个文件夹中的ID的迭代(称为historyfolter)(称为historyfolter),

$path2 = 'C:\Users\user\main folder\historyfolder'

我如何删除文件夹在$ PATH的“文件夹”和$ PATH2(即以前已经填充的ID)中。请注意,这是一个棘手的,因为文件夹确实需要相同以删除。 为了澄清,我想要“文件夹”所独有的MainId和子ID,因此还不存在历史悠久的福利德。所有其他都需要删除

PS。因为路径很棘手(主文件夹之间的空间):

$path -replace ' ', '` '
$path2 -replace ' ', '` '

有人应对挑战吗?

示例文件夹结构: in'c:\ user \ user \ user \ main文件夹\文件夹':

  • id 1,包含2个子ID:ID A,ID B
  • ID 2,包含2个子ID:ID C,ID D
  • ID 3,... ID 4,...
  • ID 4,... ...

示例文件夹结构: 在'c:\ user \ user \ main文件夹\ history folder':

  • id 2,包含2个子ID:ID C,ID D
  • ID 44,...
  • ID 55,...

预期结果中的预期结果:

  • ID 1,所有目录
  • ID 3,所有内容
  • ID 4,所有内容

Let's say that I have a folder which contains many subfolders with mainIDs and SubIDs into those mainID folders:

$path = 'C:\Users\user\main folder\folder'

So for example

$IDs = 'C:\Users\user\main folder\folder\mainID'
$SubIDs = 'C:\Users\user\main folder\folder\mainID\subID'

What I also have is another folder which contains a previous iteration of IDs saved in another folder (called historyfolder)

$path2 = 'C:\Users\user\main folder\historyfolder'

How do I delete folders that are in the "folder" of $path AND $path2 (i.e. IDs that were previously already populated). Note that it is a tricky one, as the folders really need to be identical to be removed.
To clarify, I want mainIDs and subIDs that are unique to "folder", so not existing yet in the historyfolder. All others need to be removed

Ps. because the path is tricky (space between main folder) I used:

$path -replace ' ', '` '
$path2 -replace ' ', '` '

Anyone up for the challenge?

Example folder structure:
In'C:\Users\user\main folder\folder':

  • ID 1, contains 2 sub IDs: ID A, ID B
  • ID 2, contains 2 sub IDs: ID C, ID D
  • ID 3, ...
  • ID 4, ...

Example folder structure:
In 'C:\Users\user\main folder\historyfolder':

  • ID 2, contains 2 sub IDs: ID C, ID D
  • ID 44, ...
  • ID 55, ...

Expected result in folder:

  • ID 1, with all contents
  • ID 3, with all contents
  • ID 4, with all contents

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文