Solved

Powershell script to output a list of files that are in folders and subfolers.

Posted on 2011-09-30
2
485 Views
Last Modified: 2012-08-13
Hi,

I need to write a power shell script that will output to a text file all the files that are in a directory including files in sub folders. .

Thanks

Luke
0
Comment
Question by:luketr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
KenMcF earned 500 total points
ID: 36891024

You can use the recurse switch to get all subfolder and then pipe to where to check if it is a file or folder.

Get-ChildItem c:\temp -Recurse | Where {$_.PSISContainer -ne $True} | out-file c:\temp\files.txt

Or CSV File

Get-ChildItem c:\temp -Recurse | Where {$_.PSISContainer -ne $True} | export-csv c:\temp\files.csv
0
 
LVL 69

Expert Comment

by:Qlemo
ID: 36891061
Since PSIsContainer is a boolean value, it is more straightforward to omit comparision (which is redundant):
Get-ChildItem c:\temp -Recurse | Where {!$_.PSIsContainer} | out-file c:\temp\files.txt

Open in new window

You can use aliases, which are a matter of taste:
gci c:\temp -recurse | ? {!$PSIsContainer] | out-file c:\temp\files.txt

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question