繁体   English   中英

Powershell 脚本仅将子文件夹中的文件移动到另一个位置,一次一个子文件夹

[英]Powershell script to move only files in subfolder to another location ,one subfolder at a time

我正在研究 PowerShell 脚本,我们需要将子文件夹中的文件移动到另一个位置,一次移动一个子文件夹,即移动子文件夹 1 中的文件,等待 10 分钟然后移动子文件夹 2 中的文件。脚本将文件全部移动子文件夹

Get-ChildItem –Path "C:\PS\"*.HTML -Recurse | Foreach-Object {
    Move-Item $_.FullName -Destination E:\work\tst.txt
}

文件夹结构:

Parent folder
  Child1
     file1.txt
     file2.txt
     file3.txt
Child2
     file1.txt
     file2.txt
     file3.txt
Child3
     file1.txt
     file2.txt
     file3.txt

然后使用Get-ChildItem发现每个子文件夹:

Get-ChildItem -Path C:\PS -Directory |ForEach-Object {
  # move files from this folder to destination
  $_ |Get-ChildItem -File |Move-Item -Destination E:\work\ -Force

  # wait 10 minutes
  Start-Sleep -Seconds 600
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM