2

我有一台 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脚本或批处理文件。

4

2 回答 2

4

我遇到了大致相同的问题。我写了这样的东西:

$category_list = Get-ChildItem *\*\*

Get-ChildItem *\*\*\* | % { Move-Item $_.FullName (($_.Parent).Parent).FullName }

$category_list | Remove-Item -Recurse
于 2013-04-11T15:23:57.757 回答
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 ..
)
于 2013-04-11T15:46:16.500 回答