- Enumerate and query files and folders
- Prerequisites
- Enumerate files and folders in a location
- Query files in a location and enumerate matching files
- The easy way to print a list of folders and files in Windows
- Windows 10 Instructions
- Windows 2012 Server Instructions
- Found this useful? Please share:
- Watch Gary in action
- Reader Interactions
- Comments
- How to print list of Files in a Folder in Windows 10
- Print list of files in a folder in Windows 10
- 1] Using Command Prompt
- 2] Using Paint
- 3] Use a freeware
- List Files in Folders and Subfolders with PowerShell
- Listing files in folders and subfolders with PowerShell
- Listing a specific folder
- Use the –Recurse switch
- Easy sorting
Enumerate and query files and folders
Access files and folders in either a folder, library, device, or network location. You can also query the files and folders in a location by constructing file and folder queries.
For guidance on how to store your Universal Windows Platform app’s data, see the ApplicationData class.
В For a complete sample, see the Folder enumeration sample.
Prerequisites
Understand async programming for Universal Windows Platform (UWP) apps
You can learn how to write asynchronous apps in C# or Visual Basic, see Call asynchronous APIs in C# or Visual Basic. To learn how to write asynchronous apps in C++/WinRT, see Concurrency and asynchronous operations with C++/WinRT. To learn how to write asynchronous apps in C++/CX, see Asynchronous programming in C++/CX.
Access permissions to the location
For example, the code in these examples require the picturesLibrary capability, but your location may require a different capability or no capability at all. To learn more, see File access permissions.
Enumerate files and folders in a location
В Remember to declare the picturesLibrary capability.
In this example we first use the StorageFolder.GetFilesAsync method to get all the files in the root folder of the KnownFolders.PicturesLibrary (not in subfolders) and list the name of each file. Next, we use the StorageFolder.GetFoldersAsync method to get all the subfolders in the PicturesLibrary and list the name of each subfolder.
In C# or Visual Basic, remember to put the async keyword in the method declaration of any method in which you use the await operator.
Alternatively, you can use the StorageFolder.GetItemsAsync method to get all items (both files and subfolders) in a particular location. The following example uses the GetItemsAsync method to get all files and subfolders in the root folder of the KnownFolders.PicturesLibrary (not in subfolders). Then the example lists the name of each file and subfolder. If the item is a subfolder, the example appends «folder» to the name.
Query files in a location and enumerate matching files
In this example we query for all the files in the KnownFolders.PicturesLibrary grouped by the month, and this time the example recurses into subfolders. First, we call StorageFolder.CreateFolderQuery and pass the CommonFolderQuery.GroupByMonth value to the method. That gives us a StorageFolderQueryResult object.
Next we call StorageFolderQueryResult.GetFoldersAsync which returns StorageFolder objects representing virtual folders. In this case we’re grouping by month, so the virtual folders each represent a group of files with the same month.
The output of the example looks similar to the following.
The easy way to print a list of folders and files in Windows
Windows 10 Instructions
- In Windows Explorer go to the location of the folder which you want to print a contents list.
- Press Alt -> D on your keyboard (the address bar of Windows Explorer will now be in focus).
- Type cmd and press Enter. (the command prompt will open in the path that you chose above).
- Copy and paste the following to the command prompt:
dir > files_and_folders.txt - Press Enter on your keyboard.
In your directory you’ll now have a file called files_and_folders.txt that lists your folders and files.
Windows 2012 Server Instructions
- In Windows Explorer go to the location of the folder which you want to print a contents list.
- Press Shift and alternate mouse click on your folder in Windows Explorer
- Click Open command window here.
- Copy and paste the following to the command prompt:
dir > files_and_folders.txt - Press Enter on your keyboard.
Per the Windows 10 instructions, you’ll now have a file called files_and_folders.txt that lists your folders and files.
Found this useful? Please share:
Watch Gary in action
How to create a lead-capture form with file download.
How to target your most engaged Mailchimp contacts.
Reader Interactions
Comments
Try the freeware program “YourDir”. It is a little quirky (you can only export to a csv. file) but it does the job fairly fast and accurately. I’ve used it since my early XP days and it still works just fine in windows 10. I’ve been able to get a complete listing of files on directory trees with 100,000 files and subdirectories.
excellent tips – thanks!
The Windows 10 advice above worked great and really bailed me out. Somewhat amazing though that you can’t really do this in Windows 10 with a menu option as you might expect. You have to execute an MS/DOS command from the command window to get it done. Wow.
Unworkable unless you know how windos 10 works. I didn’t, so the tipe was useless. Sorry
HAVE THE FILE “FOLDERS AND FILES” BUT IT WOULDN’T OPEN UNTIL I CHOSE “OPEN IN MSWORD.” THANKS FOR THE HELP.
Doesnt work alt D on windows 10
I’m running Windows 10 and Alt-D works for me.
Alt-D wants to delete the folder. Windows 10 here as well.
thanks! this worked for me as well
Is there a way to get the entire tree, including subdirectories and sub-subdirectories?
thank you. im in shock. ive been using windows since like day one and I never knew this. it just shows that you can always learn. its so useful too. really im in shock that I never knew this. im a programmer, have been for over 35 years and it still amazes me that you can learn something new every day. just shows I should read more instruction documents lol thanks mate
I just tried this, but all it gave me was a list of 20 recent files, not a list of all the files in the folder I chose.
Thanks a lot, perfect!
Does not work with UNC Names as cmd does not support UNC naming.
I get “access denied” from one external disk when i hit “all files and folders”
Does not work with UNC Names – just map it as a network drive and it works.
In XP(?) you could print the entire file tree. How can this be done in Windows 10? Other than downloading & using an outside app?
nice tip. Try also “tree /f /a > file.txt” for a nicely formatted tree
Thanks. That was very helpful.
If the methods above are not working, try this:
From the start button, select Windows Accessories
Click on Notepad in the Widows Accessories list to open it.
In Notepad, select File and then select Open.
In the Open dialog box, navigate to the folder whose contents you want to print.
When the folder is selected, a file is displayed called “printit”.
Double-click the printit file.
You can now print or copy the text. 🙂
actually not useless and works the same in windows 7 as it does in windows 10. just follow it thru, have to right click to paste as you cannot ctrl v the entry.
yes! simply add “/s” to include subdirectories, here are a couple options 1) “dir *.*/s>myfile.txt” will give you all directories and files 2) “dir *./s>myfile.txt” for directories only (and other files with no extension, notice there’s no asterisk after the dot). For those who are unfamiliar with doing this in any version of windows, simply run the “Command Prompt” application, from there enter the drive letter you want “O:”, then change to the target directory “CD mystuff\coolfiles”, then you can simply execute the “Dir” command above. I hope this helps.
AhHA! Brilliant! Thank you!
Yes, this works nicely! Displays all subfolders and files.
Great tip for the tree …
Yes, just add “/s” to the command, to indicate you want subdirectories. You might get a large report though!
Rather than going to a DOS cmd prompt, or capturing an printing an image of a directory as other sites advise, use your browser. CMD prompts require exact syntax. This can be a frustrating challenge when directories are deeply nested in the file system. And of course, capturing an image of a directory listing and printing it is not the same as printing an actual list of files in a directory which you might want to modify for presentation: Here is the easiest way to get an editable and printable file listing: In your browser enter: file:///C:/Users/Home/[directoryname]/. Then print it, or copy/paste the HTML page elsewhere.
The tree format is so nice…thanks!
change entry to dir/s > (you can use any text here).txt press enter. It will list the all files from the root.
Alt+D and cmd – if I knew it before! thank you Gary.
what it will do is make the address in the address bad highlight. Then you just type in the cmd and hit enter, and it will open a new window. They probably could have used some illustrations or screen shots to show how to do it. However, if does work with Windows 10.
This worked perfectly in Win 10 instead of “dir > files_and_folders.txt” as written at the top of the page which only seemed to give me the file and folder names in the directory I targeted.
This gave a full file list of everything in the directory and sub directories.
I started programming back when we used BASIC and FORTRAN, so DOS doesn’t frighten me all that much. What I find amazing is the fact that it never occurred to anyone that being able to print out what is essentially a Table of Contents/Index might be a useful thing? Because, having to go through all of this is quite ridiculous.
It’s A List. We live on lists — thrive on list — and we can’t print one?
Here is the EASIEST way to print a listing of your folder:
02. Create a directory named ‘TEMP’ in your C:\dirive if you don’t have one already. Use CAPS in your directory name.
03. Copy and paste this batchfile to the directory of which you want a listing.
04. Highlight the batchfile name and press ‘Enter’.
05. In a flash, the batchfile will complete its task.
06. Navigate to C:\TEMP.
07. A file named ‘directory’ will be there.
08. Open with either Notepad or your favourite wordprocesser.
09. The listing of all the fiiles, including other details, will be there.
/
10. Edit it to your heart’s content and save it as you wish.
I’ve tried all of the suggestions in DOS and get “Access is Denied” each time. How do I allow the system to let me access my own laptop?
How to print list of Files in a Folder in Windows 10
If you ever need to print a list of files in a folder on your Windows 10/8/7 computer, here are a few ways you can do it. You can use the Command Prompt, Paint or a free software.
Print list of files in a folder in Windows 10
You can use any of the following methods to print a list of Files in a Folder in Windows 10.
- Run the Dir List command
- Use Paint software
- Use a freeware.
Let us see these methods in detail.
1] Using Command Prompt
Open the folder whose list of contents you want to print. Hold down Shift and right-click to open the hidden context menu items. You will see Open command window here. Click on it to open a command prompt window.
Else simply type CMD in the address bar and hit Enter to open the command prompt window there.
In the CMD type the following and press Enter:
A notepad text file will be immediately created in this folder. Open List.txt, and you will be able to see the list of the files in this folder.
Alternatively, you could also use the cd/ command to change the directory from the User directory to Downloads directory as follows:
2] Using Paint
Open the directory whos contents list you want to print. Select the Lists view. Press Alt+PrntScr. Next, open the built-in Paint application. Click Ctrl+V to copy-paste the contents of the clipboard here.
Now from the File menu of Paint select Print.
3] Use a freeware
You can print the name of every file on a drive, along with the file’s size, date and time of last modification, and attributes, Read-Only, Hidden, System, and Archive, with Karen’s Directory Printer. You can also sort the list of files by name, size, date created, date last modified, or date of last access. You can download it from its home page.
A) Simple File Lister does the function of DIR command for Windows OS to get a list of files in a directory and save them with their attributes to the user, in chosen .TSV, .CSV or .TXT formats, which you can then print. You can also select the File Attributes to be printed.
B) InDeep File List Maker lets you create and print a list of files in your folders, drives, and even in your DVDs/CDs.
D) Startup Discoverer is a portable freeware application, which lists start-up file & program locations and allows you to save and print them.
List Files in Folders and Subfolders with PowerShell
February 3rd, 2014
Summary: Use Windows PowerShell to list files in folders and subfolders.
Hey, Scripting Guy! I am an old VBScript guy. I love using VBScript, and I have done so for nearly 15 years. One reason I love VBScript so much is that, to me, it is easy to use. It is also very powerful. But after attending TechEd the last several years, it appears that Microsoft is moving away from VBScript, and is embracing Windows PowerShell.
So, I am trying to learn Windows PowerShell. What I am doing is when I need to make a change to an existing VBScript script, I attempt to use Windows PowerShell to do the same task. I am having a bit of trouble listing files in folders and in subfolders. Can you give me a push in the right direction?
Hello TJ,
Microsoft Scripting Guy, Ed Wilson, is here. This morning I am sipping a cup of English Breakfast tea. I added a combination spoonful of spearmint leaves, peppermint leaves, licorice root, rose hips, hibiscus, and a cinnamon stick to my pot while I steeped it for four minutes. The tea is very refreshing. Speaking of refreshing, I believe you will find the way that Windows PowerShell handles files and folders a welcome change from the work you had to do in VBScript.
First let me say that I do not hate VBScript. I wrote three books about VBScript, and I had a lot of fun teaching VBScript classes all over the world when I was in MCS. I am not the type of person who wants to say that you should immediately change over VBScript to Windows PowerShell. The point of scripting—regardless of the language—is for automation. Scripting is a tool, a means to a destination, not the destination itself. Therefore, TJ, I believe that you are taking a logical approach to learning Windows PowerShell and preparing for the future of Windows automation.
But, nearly 10 years ago, we posted the following Hey, Scripting Guy! Blog: How Can I Get a List of All the Files in a Folder and Its Subfolders? The script, written in VBScript, was 22 lines long. It was a lot of work to understand, and for someone not really familiar with VBScript, it would be quite confusing. Here is the code—just for fun.
VBScript list files in folders and subfolders
Set objFSO = CreateObject(«Scripting.FileSystemObject»)
Set objFolder = objFSO.GetFolder(objStartFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
For Each Subfolder in Folder.SubFolders
Set objFolder = objFSO.GetFolder(Subfolder.Path)
Set colFiles = objFolder.Files
For Each objFile in colFiles
There are at least three issues with this script.
One thing to keep in mind is that if you double-click this VBScript script, you potentially will receive thousands of popup message boxes like the one shown here:
Another issue is that whether I click OK, or I click the red “X” in the upper-right corner, the onslaught of popup dialog boxes keeps coming. The only way to retrieve control of the situation (other than rebooting my computer) is to open Task Manager, find the Windows-based script host process, and kill it. This is illustrated in the following image:
The third issue is a bit different. It involves a bit of usability because to change the destination of the script, I must manually edit the script. This involves opening the script in Notepad (the only editor we ship for VBScript), and changing the value of ObjStartFolder.
Now, each of these issues is solvable in that I can check to ensure the script is running in a command prompt via Cscript, and I can add command line input variables to the script. But both of these solutions are going to involve several lines of additional code.
Listing files in folders and subfolders with PowerShell
When it comes to working with files and folders and recursing through a nested directory structure, it is almost an unfair competition between Windows PowerShell and VBScript. It is almost like the Windows PowerShell team deliberately made it easy to work with files and folders.
For example, suppose I have a series of nested folders in my music folder, such as the one shown in the following image. Each folder is a music group, each subfolder is an album, and inside each album are the individual music tracks.
Listing a specific folder
To work with a specific folder, I use the Get-ChildItem cmdlet. This cmdlet has been around since Windows PowerShell 1.0, but in more recent versions of Windows PowerShell, it has gained a couple of additional useful switches. First, just list a specific folder:
Get-ChildItem -Path E:\music
This command lists all files and folders that are at the E:\music level. This command does not recurse through the entire structure. The command and a sample output are shown in the following image:
If I want to only see the folders at this level, I use the –Directory switch.
Note The –Directory, -File, -Attributes, -Hidden, and –System switches were added to Get-ChildItem cmdlet in Windows PowerShell 3.0. These switches are available via the FileSystem provider. For more information, see Use PowerShell to Find Dynamic Parameters.
This would be the command to see only the directories at the E:\Music level:
Get-ChildItem -Path E:\music –Directory
To see only the files at this level, I change it to use the –File switch:
Get-ChildItem -Path E:\music –File
Use the –Recurse switch
To burrow down into a nested folder structure, I need to use the –Recurse switch. The difference is readily apparent. For example, the following command displays the folders in a specific folder:
Get-ChildItem -Path E:\music\Santana
The output from the command is shown here:
When I use the –Recurse switch, I can see the folders in addition to the files inside each of the folders. The command is shown here:
Get-ChildItem -Path E:\music\Santana –Recurse
In the following image, I see that at first the output is the same—it lists the folders. Then it takes each folder in turn, and displays the files from that folder. This continues until all the files in all the nested folders are displayed.
If I use the –File parameter, I do not get the initial folder list:
Get-ChildItem -Path E:\music\Santana -Recurse –File
The command and output from the command are shown here:
Easy sorting
One of the really cool things that Windows PowerShell does is makes it easy to sort information. There is even a cmdlet named Sort-Object. For example, if I want to see which songs are the longest, I would use this command:
Get-ChildItem -Path E:\music\Santana -Recurse -File | sort length –Descending
The command and output from the command are shown here:
TJ, that is all there is to using Windows PowerShell to list files in folders and subfolders. Join me tomorrow when I will talk about more cool Windows PowerShell stuff.