How to print contents of a directory and save it NOT in the directory?

-1

I have a folder which freezes the whole system when I open it (probably there is a corrupted file). Luckily, I'm just interested in the names of the files in the folder.

So, how do I create a dirlist.txt from a folder in Powershell and at the same time not save it in the folder itself? Because if I do that, I won't be able to reach the dirlist. Thanks a lot!

RichardTheCoder

Posted 2018-06-17T20:33:49.437

Reputation: 3

Answers

0

Just pipe the output to a particular folder. Using the PowerShell or old CMD prompt.

dir "c:\program files"> c:\junque\mystuff.txt

will list the contents of the C:\Program Files folder and, assuming the folder C:\junque exists and that you have access to it, list the files in the document mystuff.txt.

DrMoishe Pippik

Posted 2018-06-17T20:33:49.437

Reputation: 13 291

0

Get-ChildItem C:\folder\ | Out-File C:\dirlist.txt

The first path is the folder you want to get the items of. You can also add the -Recurse flag if there are subfolders you'd like to get the items of.

root

Posted 2018-06-17T20:33:49.437

Reputation: 2 992

I'd add the parameter -ErrorAction SilentlyContinue or short -EA 0 to the gci. – LotPings – 2018-06-18T11:23:45.493