我有一台Windows server 2008机器,我有一个像
这样的文件夹结构root_folder
...........username1
....................project1
............................category
....................................subproject1
....................................subproject2
....................................subproject3
....................project2
............................category
....................................subproject1
....................................subproject2
....................................subproject3
...........username2
....................project1
............................category
....................................subproject1
....................................subproject2
....................................subproject3
....................project2
............................category
....................................subproject1
....................................subproject2
....................................subproject3
现在我需要做的是删除类别文件夹并直接在相应的项目(x)文件夹下复制其内容。有点像这样
root_folder
...........username1
....................project1
....................................subproject1
....................................subproject2
....................................subproject3
....................project2
....................................subproject1
....................................subproject2
....................................subproject3
-----------------------------------------------------------
...........username2
....................project1
............................subproject1
............................subproject2
............................subproject3
....................project2
............................subproject1
............................subproject2
............................subproject3
-----------------------------------------------------------
如何使用powershell脚本完成此操作。还有什么是最好的PowerShell脚本或批处理文件。
答案 0 :(得分:3)
我有同样的问题。我写了这样的话:
$category_list = Get-ChildItem *\*\*
Get-ChildItem *\*\*\* | % { Move-Item $_.FullName (($_.Parent).Parent).FullName }
$category_list | Remove-Item -Recurse
答案 1 :(得分:1)
编辑:我添加了一项修改,以便同时移动类别文件夹中的文件。
@echo off
rem Enter into Root Folder
cd \root_folder
rem Process each User Name folder
for /D %%u in (*) do (
rem Enter into the user name folder
cd "%%u"
rem Process each Project
for /D %%p in (*) do (
rem Enter into the category of this project
cd "%%p\category"
rem Move all subprojects one level up
for /D %%s in (*) do move "%%s" ..
rem Move all files one level up
move *.* ..
rem Go back one level up to project folder
cd ..
rem Remove the now empty category folder
rd category
rem Go back one level up to user folder
cd ..
)
rem Go back one level up to root folder
cd ..
)