user3586898
user3586898

Reputation: 199

Copying file names to a text file in PowerShell

I've currently got a PowerShell script that copies the file names in a directory to a text file. It excludes .info files from the copy. This is my code as it stands:

Get-ChildItem -Path "C:\Test\" -Recurse -name -exclude '*.info' | out-file C:\Test.txt

I need to dump out a different text file for each individual file it copies the name of, with the name of the text file that of the name it copies.

I've done a lot of reading and still can't seem to find a resolution. How can I fix it?

Upvotes: 4

Views: 11731

Answers (1)

Diligent Key Presser
Diligent Key Presser

Reputation: 4253

Get-ChildItem -Path "D:\Projects" -Recurse -exclude '*.info' | ForEach { [System.IO.File]::WriteAllText("C:\test\"+ $_.Name + ".txt", $_.FullName)}

Upvotes: 3

Related Questions