2016-01-21 118 views
1

我使用Windows命令行導出目錄中所有文件的列表,包括完整路徑。命令是:Powershell Get-ChildItem命令

DIR /b/s/n/a:-d/o:>"C:\Users\user\Desktop\file_list.txt"  
/b to list only files and folder with no additional information; 
/s to list all files within the subfolders;  
/n to list long names (here is my problem, it still list max. 255 char);  
/a:-d to not list directories without files;  
/o to sort files. 

我想在PowerShell上運行類似的命令,但要列出超過255個字符的文件。

任何人都可以幫忙嗎?

回答

0
  1. 使用Get-ChildItem cmdlet與-recurse開關 從一個特定的路徑檢索的所有文件和文件夾。
  2. 使用Where-Object排除所有空目錄 ($_.PSIsContainer等於true,文件數大於零)。使用Select-Object來選擇FullName的項目。
  3. 使用Out-File cmdlet可將結果存儲在文件中。

實施例:

Get-ChildItem C:\Users\ -recurse | 
    Where-Object {(($_.PSIsContainer -eq $false) -or (($_.PSIsContainer -eq $true) -and ($_.GetFiles().Count -gt 0)))} | 
    Select-Object FullName | 
    Out-File 'C:\Users\user\Desktop\file_list.txt'