所以,我有這樣的目錄結構:
parent/
└── sub1
| └── sub1.1
| | └── source
| | └── something1
| | └── something2
| |
| └── sub1.2
| └── source
| └── something3
| └── something4
└── sub2
└── sub2.1
| └── source
| └── something5
| └── something6
|
└── sub2.2
| └── source
| └── something7
| └── something8
|
└── sub2.3
└── source
└── something9
└── something10
我想將所有檔案(具有不同的檔案名稱)從所有名為 source 的目錄移動到其相對上/父目錄。所以,結果應該是這樣的:
parent/
└── sub1
| └── sub1.1
| | └── something1
| | └── something2
| |
| └── sub1.2
| └── something3
| └── something4
└── sub2
└── sub2.1
| └── something5
| └── something6
|
└── sub2.2
| └── something7
| └── something8
|
└── sub2.3
└── something9
└── something10
有一個linux範例,但我想要一個批次版本。
編輯:謝謝,那應該可行。我最初有以下內容,但它只會執行一個子資料夾的深度。
@echo off
for /D %%I in ("%~dp0*") do (
if exist "%%I\source\*" (
move /Y "%%I\source\*" "%%I\" 2>nul
rd "%%I\source" 2>nul
)
)
答案1
這是一個小的 C# 程式。
using System;
using System.IO;
namespace Move {
class Program {
static void Main(string[] args) {
Console.Write("Folder: ");
string path = Console.ReadLine();
foreach (var folders in Directory.GetDirectories(path)) {
Console.WriteLine(folders);
foreach (var subs in Directory.GetDirectories(folders)) {
Console.WriteLine($"\t{subs}");
foreach (var source in Directory.GetDirectories(subs)) {
Console.WriteLine($"\t\t{source}");
foreach (var item in Directory.GetFiles(source)) {
Console.WriteLine($"\t\t\t{item}");
string filename = Path.GetFileName(item);
string newPath = $@"{subs}\{filename}";
File.Move(item, newPath);
}
Directory.Delete(source);
}
}
}
Console.ReadLine();
}
}
}