Solved

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

Posted on 2011-09-30
2
487 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 70

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

More Than Just A Video Library

Train for your certification. Learn the latest DevOps tools. Grow your skillset to do better work.

At Linux Academy, we release new training modules every week so you'll always be up to date on the latest tech.

Question has a verified solution.

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

A procedure for exporting installed hotfix details of remote computers using powershell
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

729 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