2

有很多子文件夹,只需要为二阶子文件夹创建目录连接。

当前文件夹结构的某些部分如下所示

C:\MainFolder>tree
Folder PATH listing for volume C System
C:.
├───1stSub-FolderA
│   ├───2ndSub-FolderA
│   └───2ndSub-FolderB
└───1stSub-FolderB
    ├───2ndSub-FolderA
    └───2ndSub-FolderB

D:\MainFolder-Copy>tree
Folder PATH listing for volume Dosya
D:.
├───1stSub-FolderA
└───1stSub-FolderB

每个文件夹的手动编码:

C:\>mklink /j D:\MainFolder-Copy\1stSub-FolderA\2ndSub-FolderA C:\MainFolder\1stSub-FolderA\2ndSub-FolderA
Junction created for D:\MainFolder-Copy\1stSub-FolderA\2ndSub-FolderA <<===>> C:\MainFolder\1stSub-FolderA\2ndSub-FolderA

C:\>mklink /j D:\MainFolder-Copy\1stSub-FolderA\2ndSub-FolderB C:\MainFolder\1stSub-FolderA\2ndSub-FolderB
Junction created for D:\MainFolder-Copy\1stSub-FolderA\2ndSub-FolderB <<===>> C:\MainFolder\1stSub-FolderA\2ndSub-FolderB

C:\>mklink /j D:\MainFolder-Copy\1stSub-FolderB\2ndSub-FolderA C:\MainFolder\1stSub-FolderB\2ndSub-FolderA
Junction created for D:\MainFolder-Copy\1stSub-FolderB\2ndSub-FolderA <<===>> C:\MainFolder\1stSub-FolderB\2ndSub-FolderA

C:\>mklink /j D:\MainFolder-Copy\1stSub-FolderB\2ndSub-FolderB C:\MainFolder\1stSub-FolderB\2ndSub-FolderB
Junction created for D:\MainFolder-Copy\1stSub-FolderB\2ndSub-FolderB <<===>> C:\MainFolder\1stSub-FolderB\2ndSub-FolderB

结果:

C:\MainFolder>tree
Folder PATH listing for volume C System
C:.
├───1stSub-FolderA
│   ├───2ndSub-FolderA
│   └───2ndSub-FolderB
└───1stSub-FolderB
    ├───2ndSub-FolderA
    └───2ndSub-FolderB

D:\MainFolder-Copy>tree
Folder PATH listing for volume Dosya
D:.
├───1stSub-FolderA
│   ├───2ndSub-FolderA
│   └───2ndSub-FolderB
└───1stSub-FolderB
    ├───2ndSub-FolderA
    └───2ndSub-FolderB

如何使用一些命令为所有二阶子文件夹创建它,而不是为每个文件夹手动编写代码?命令不应为第 1、第 3、第 4、第 5 .. 顺序子文件夹创建目录连接。

4

1 回答 1

5

试试这个:

Get-ChildItem D:\MainFolder-Copy -Directory |
    Foreach {Get-ChildItem (Join-Path C:\MainFolder $_.Name) -Directory} | 
    Foreach {cmd /c mklink /j ($_.FullName -replace 'C:\\MainFolder','D:\MainFolder-Copy') $_.FullName}
于 2013-11-04T18:16:24.057 回答