Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write file names from loop to text file

Tags:

powershell

$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.

like image 205
mkrouse Avatar asked Jul 15 '13 20:07

mkrouse


1 Answers

I tested this, and it worked for me:

Get-childitem -path "C:\" -recurse -name | out-file C:\Output.txt
like image 80
Kevin_ Avatar answered Nov 03 '22 01:11

Kevin_