?
Solved

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

Posted on 2011-09-30
2
Medium Priority
?
488 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 2000 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

WatchGuard's M Series Appliances - Miecom Approved

WatchGuard's newest M series appliances were put to the test by Miercom.  We had great results and outperformed all of our competitors in both stateless and stateful traffic throghput scenarios! Ready to see how your UTM appliance stacked up? Download the Miercom Report!

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.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

752 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