3
在Windows shell中,您可以使用類似copy c:\filename NUL
的命令獲取文件的內容並將其複製到「\ Device \ Null」。 (這是回顧外部歸檔文件,而無需浪費空間或touch
更新有用的。)
但使用$null
,NUL
,\\.\NUL
多(我想不出如何做相同的PowerShell和我不t想要調出一個單獨的CMD.EXE進程來爲每個文件執行此操作)。
PS C:\> Copy-Item -Path .\filename -Destination NUL
Copy-Item : Cannot process path 'C:\NUL' because the the target represents a reserved device name.
At line:1 char:10
+ Copy-Item <<<< -Path .\filename -Destination NUL
+ CategoryInfo : WriteError: (C:\NUL:String) [Copy-Item], IOException
+ FullyQualifiedErrorId : CopyError,Microsoft.PowerShell.Commands.CopyItemCommand
PS C:\> Copy-Item .\filename NUL
Copy-Item : Cannot process path 'C:\NUL' because the the target represents a reserved device name.
At line:1 char:10
+ Copy-Item <<<< .\filename NUL
+ CategoryInfo : WriteError: (C:\NUL:String) [Copy-Item], IOException
+ FullyQualifiedErrorId : CopyError,Microsoft.PowerShell.Commands.CopyItemCommand
PS C:\> copy .\filename '\\.\NUL'
Copy-Item : Cannot process path '\\.\NUL' because the the target represents a reserved device name.
At line:1 char:5
+ copy <<<< .\filename '\\.\NUL'
+ CategoryInfo : WriteError: (\\.\NUL:String) [Copy-Item], IOException
+ FullyQualifiedErrorId : CopyError,Microsoft.PowerShell.Commands.CopyItemCommand
任何其他的想法如何做到這一點?
這是因爲'$ null'不是Powershell中的設備/驅動器本身。猜猜'Out-Null'將不會起作用。但是我仍然沒有真正明白你想要複製到$ null的目標,你能否詳細說明一下? –
某些歸檔軟件會將實際文件數據保存到另一個遠程文件系統/數據庫/磁帶,但留下標有NTFS「脫機」屬性的小型存根。當用戶獲取文件的*內容*(而不僅僅是文件屬性)時,軟件從存檔中獲取並恢復本地文件。因此......恢復所有存根/脫機文件的最簡單方法是將它們複製到某處 - 但複製到另一個文件系統需要永久(然後您必須刪除所有廢話),而將它們複製到NUL更快。 – ewall