【发布时间】:2015-08-14 12:44:19
【问题描述】:
我正在尝试创建一个脚本,该脚本读取文件的第一行,然后将具有类似命名约定的所有文件上移一个级别。
这些是 3 个示例文件:
C:\Users\USERNAME\location\PYYYYYYYYY.txt.asc
C:\Users\USERNAME\location\holdingarea\PYYYYYYYYY.tt.asc
C:\Users\USERNAME\location\holdingarea\PYYYYYYYYY.t.asc
我目前的脚本是:
$location = Read-Host -Prompt "Location Filename"
$locationfilename = Select-String C:\Users\USERNAME\location\holdingarea\*.txt.asc –pattern $location -Context 1
$locationfilenames = $locationfilename.basename
$locationarea = "C:\Users\USERNAME\location\holdingarea"
$locationlocation = "C:\Users\USERNAME\location"
Select-String C:\Users\USERNAME\location\holdingarea\*.txt.asc -Pattern $location -Context 1 |
Out-File -Append C:\Users\USERNAME\location\logs.txt
Move-Item -Path "$locationfilenames" -Destination "$locationlocation"
【问题讨论】:
-
为
$locationlocation加1 -
您的脚本有什么问题?
-
它带回以下错误,移动项目:找不到驱动器。名称为“> C”的驱动器不存在。在 line:10 char:10 + Move-Item C:String) [Move-Item], DriveNotFoundException + FullyQualifiedErrorId : DriveNotFound, Microsoft.PowerShell.Commands.MoveItemCommand
标签: powershell file-move