5
$fileEntries = [IO.Directory]::GetFiles("C:\Users\U0146121\Desktop\Example Data"); #where the file is located.
foreach($fileName in $fileEntries) 
{ 
 #write the file name to a text file.  
}  

I need to write the file name to a text file within the loop but I'm not sure how to.

Eventually I will read the text file and search the filenames in excel. But for now I have to write the .txt file first.

2
  • Are you wanting the name of a bunch of files in a directory? Commented Jul 15, 2013 at 20:51
  • yeah just the file name Commented Jul 15, 2013 at 21:12

1 Answer 1

15

I tested this, and it worked for me:

Get-childitem -path "C:\" -recurse -name | out-file C:\Output.txt
Sign up to request clarification or add additional context in comments.

1 Comment

Is there anyways to output it to the text file without the header and spaces?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.