Thursday, February 8, 2018

How Write the name of all contents of a folder to a file in Powershell



Write the name of all contents of a folder to a file using powershell



$files = Get-ChildItem -Path 'D:\doc\' -Recurse |?{$_.PSIsContainer -eq $false -and $_.Extension -ne '.txt'  }

"Total : "+$files.Count+" files" | Out-File -Append 'D:\doc\MyFiles.txt'
ForEach($file in $files)
{
 $file.Name | Out-File -Append 'D:\doc\MyFiles.txt'  
}

  

This is just a trick, hope it paved your way out. 

No comments:

Post a Comment