File listing to excel

Содержание

  1. How to Copy a List of Files in a Windows Folder Into an Excel List
  2. Related
  3. 2 Methods to Copy the List of All File Names in a Folder into Your Excel Worksheet
  4. Method 1: Use a New Text Document
  5. Method 2: Define Name
  6. A Comparison of the Two Methods
  7. Take Actions Quickly in a Data Disaster
  8. List of all Files and Folders: How to Easily Insert a Directory in Excel!
  9. Summary
  10. Method 1: Simply copy and paste from Mac Finder to Excel
  11. Method 2: Insert a file list with built-in Excel functions using “Named Ranges”
  12. Set up the named range
  13. Use the named range in Excel functions
  14. Method 3: Use an internet browser to quickly copy and paste a file list to Excel
  15. Method 4: Create a file list with PowerQuery
  16. Method 5: Excel Add-in Professor Excel Tools
  17. Method 6: Use PowerShell to extract a file list
  18. Open PowerShell and write the directory into a text file
  19. Import text file into Excel
  20. Method 7: Let a VBA Macro loop through the files
  21. Download

How to Copy a List of Files in a Windows Folder Into an Excel List

Maintaining an Excel spreadsheet of computer files can help you keep track of important business documents or images. Unfortunately, Microsoft Excel doesn’t include a one-step method for importing a file list from Windows Explorer, but Windows 7 offers an easy workaround. Using the Command Prompt, you can tell Windows to output a text document containing a directory list. This text document can then be imported into Excel and modified just like any other spreadsheet.

Press «Win-E» to open Windows Explorer and locate the folder for which you need a file list.

Hold the «Shift» key, right-click the folder and select «Open Command Window Here.» This only works with folders, not libraries. Libraries point to a specific folder, so select the folder located under the library icon. If the library points to a drive, right-click the drive letter from the folder tree.

Type «dir /b > dirlist.txt» without quotes and press «Enter.» This creates a list containing file names only. To include file sizes and dates, type «dir > dirlist.txt» instead. To also include files in sub-directories, type «dir /b /s > dirlist.txt» to create a list of files with the full directory structure name, such as «C:foldersubdirectoryfile.txt.»

Open Microsoft Excel and press «Ctrl-O» to bring up the Open dialog window.

Navigate into the folder containing the files. Click the file type drop-down menu and select «Text Files (.prn,.txt,*.cvs).» Double-click «dirlist.txt» to open it.

Click «Finish» in the Text Import Wizard window to use the default options and import the directory list into Excel.

Источник

2 Methods to Copy the List of All File Names in a Folder into Your Excel Worksheet

Sometimes you will need to list all the file names in a folder in an Excel worksheet. Thus, you can better manage those files. In this article, we will introduce two effective methods to copy the list in a folder.

In an Excel worksheet, you can make a menu of some important files. And you need to copy the list of all the file names into one worksheet. However, when there are hundreds or thousands of files, you will find it hard to do this. In the image below, you can see several files.

Now you need to copy the list of all the file names into a worksheet in another Excel file. If you copy and paste them one by one manually, you will certainly spend a lot of time and energy. At this time, you can use the two methods below.

Method 1: Use a New Text Document

Now follow the steps below and see how this method takes effect.

  1. Before you perform this process, make sure that you have shown the file extensions in your computer. Click the button “Start” in your computer.
  2. And then click the button “Control Panel”.
  3. In the control panel, click the “Appearance”.
  4. And then click the button “Folder Options”.
  5. After that, choose the option “View” in the “Folder Options” window.
  6. Next uncheck the option “Hide extension for known file types”.
  7. And then click “OK” to save the setting.

Therefore, you can see all the extensions of files in your computer.

  1. Come back to the folder, create a new text document and give it a new name. We will name it “DataNumen Sales Volume”.
  2. And then open this text file.
  3. After that, input the following characters into this file:

  1. Next save this file and close it.
  2. In this step, change the extension of this file from “.txt” into “.bat”.
  3. After that, you will see a new window pop up. Here you need to click the button “Yes” to confirm this change.
  4. And then double click this file again. Next you will see a new text document with the name “1” in this folder.
  5. Open this new text document in this folder. You will see all the name information in it.
  6. After that, copy the necessary part in this file.
  7. And then in the target worksheet, click the small arrow under the button “Paste”.
  8. In the drop-down list, choose the option “Use Text Import Wizard”.
  9. Next in the new window, choose the option “Fixed width”.
  10. And then click the button “Next”.
  11. In step 2 of the wizard, move the break line and make sure that the names of those files will be in one cell.
  12. And then also click “Next”.
  13. In step 3, click “Finish”. Thus, all the information will appear in the worksheet.

You can delete the other useless columns in the worksheet. By using this method, you don’t have to copy and paste the names one by one.

Method 2: Define Name

In this part, we will introduce another excellent method.

  1. Click the tab “Formulas” in the ribbon.
  2. And then click the button “Define Name”.
  3. In the “New Name” window, input a name into the first text box. We will also name it “DataNumen_Sales_Volume”.
  4. After that, input this formula into the “Refers to” text box:

=FILES(“C:UsersSampleDesktopSales Volume*.*”) &T(NOW())

The path of the folder is “C:UsersSampleDesktopSales Volume” in this example. You need to change it into your actual folder path.

  1. And then click the button “OK” in the window.
  2. Now input the following formula into one cell in the worksheet:

In this formula, you need to change the define name into yours.

  1. After that, click the fill handle of this cell and drag downwards. As you move your mouse, you will also find that all the names will appear in this column.
  2. But you may also find that those results are the results of formulas. You still need to copy and paste them as texts.
  3. Next delete the formulas in the worksheet.

Until now, you have gone through all the steps. This method is also very effective for this requirement.

A Comparison of the Two Methods

You can see that both of the two methods are very useful. Here we will compare the two methods in this part.

If you are not familiar with Name and the complex formula in cells, you can use this first method. There are fewer steps in this method. You can finish your tasks quickly by using it.

Compared with the second methods, there are more steps in this method. You still need to spend a lot of time. The formulas in cells will produce the results that you need. Therefore, you still need to copy and paste them as values.

When you need to input all file names into a worksheet, you will know which method is the most suitable one.

Take Actions Quickly in a Data Disaster

It is unavoidable that you will meet with data disaster. In such an accident, your Excel files will most possibly be damaged. Therefore, you need to take actions quickly. In order to repair corrupt xls data quickly and safely, you can use out excellent Excel repair tool. This tool is able to fix most of the Excel problems.

Источник

List of all Files and Folders: How to Easily Insert a Directory in Excel!

You probably don’t need this every day: But once a file you might want to have a list of all files within a folder or directory in Excel. The good thing: There are many methods available. If you Google it, you will find a lot of different methods to create a file list in Excel. But unfortunately, all of them have advantages and disadvantages – which you usually only find out after trying them. That’s the reason for this article: You won’t only learn each method step by step: You will rather find an overview comparing all the advantages and disadvantages of each method. After seeing this, you don’t need to start extensive trials and errors. Much better: You can easily select the method that works best for you!

Summary

Method 1:
Copy & Paste on Mac
Method 2:
Named function
Method 3:
Internet browser
Method 4:
PowerQuery
Method 5:
Excel-Add-In
Method 6:
Windows PowerShell
Method 7:
VBA Macro
Short description Copy and paste from the Mac Finder. Use a function in a named range to insert a file list. Open folder with a web browser and copy the file list. Use PowerQuery to insert a directory. Let an Excel add-in do the work for you. Use the Windows built-in PowerShell feature. Use a VBA Macro to insert a file list.
Ease of use
Operating system Mac Windows Windows / Mac Windows / Mac Windows Windows Windows
Include subfolders
and files
No No No Yes Yes Yes (Yes) (depends on the VBA macro)
File information available File names File names File names, file links (not working properly), file size, date modified Folder path, name
extension, date accessed, date modified, date created
More attributes:

Links to files on the drive, file path, date and time last saved, date and time created, file size, file type File name, file path, date and time last saved, file size Depends on the VBA macro Technology Mac Finder Named function in Excel Internet browser PowerQuery Excel Add-In PowerShell, Text Import Wizard VBA Comment Fast but with limited options. Only shows files, no folders. File links not working in our test; not working with all internet browsers (tested with Google Chrome and working). Elegant and uses built-in functions. Convenient, fast and many options. Results not good, difficult process; performs well on large file structures, though. Modifying the macro rather for advanced users. Link Click here Click here Click here Click here Click here Click here Click here

Method 1: Simply copy and paste from Mac Finder to Excel

This first method works on a Mac only: Just select all files in a Finder window and press copy (Command + C on the keyboard). Next, switch to Excel and paste the list: Press Command + V on the keyboard.

The advantage of this method is that it’s very easy and fast. Unfortunately, you don’t have any further options than just pasting the file names. That means you can’t insert data of subfolders or file properties.

Recommendation: Use this if you need a quick file list on the Mac – without any further information.

Method 2: Insert a file list with built-in Excel functions using “Named Ranges”

The second method is actually quite elegant: Use built-in Excel functions to insert a file list in Excel. It is built on advanced functions, such as an Excel function within a named range. But following these steps should be quite straight-forward.

Set up the named range

  1. Choose a cell in which you later write the folder path. In this case, it’s cell C4.
  2. Click on “Defined Name” on the Formulas ribbon.
  3. Give a name for the cell containing the folder path (here: “Folder_Path”)
  4. In the “Refers to” field, type: =files(linktopathcell) (replace “linktopathcell” with your cell reference – in this case “Method_2!$C$4”).
  5. Confirm with OK.

Use the named range in Excel functions

  1. Go to the Windows Explorer and copy the folder path.
  1. Paste the folder link into the folder path cell (the cell you have set as the named range in step 1 above). Add one of the following endings:
    • If you want to include all files – no matter which file type – in your list, add *
    • For listing only Excel files, add *.xls*
    • If you want to see all files ending on “.xlsx”, add *.xlsx
  2. As the last step, enter an INDEX function for compiling the list (here in cell B7):
    =INDEX(Folder_Path,ROW(B1))
    Folder_Path should be the same name that you have given in step 3 above. The ROW function should refer to any cell in the first row (for example to B1). That means, this argument could also be A1, C1, etc.
    As the last step: Copy the INDEX function down until you see the first #REF error. #REF means in this case that there are no more files in your folder. If you like, you could wrap the IFERROR function around in order to mitigate the error.

Recommendation: Use this if you only need a list of files (no subfolders) that dynamically updates itself.

Method 3: Use an internet browser to quickly copy and paste a file list to Excel

I must say, I like this idea because it’s almost as fast as our method number 1 above: Open a folder in a webbrowser and then copy & paste the list to Excel.

  1. Copy the folder path from the Windows Explorer like on the screenshot or Mac Finder (for Mac: open file Info (right-click on folder and then on “Get Info”. Select and copy link from “Where” section).
  1. Open a browser, for example Google Chrome (should be working with most other browsers as well). Paste the previously copied link into the address field.
  2. Copy the table of files.
  3. Open Excel and paste the file list.

One comment to this methods: The links (which are also created) usually won’t work in Excel.

Recommendation: Use this if you quickly need a file list (without subfolders), including some file properties such as file size and date last saved.

Method 4: Create a file list with PowerQuery

The next method is also among my favorites: It uses PowerQuery and comes with the advantages that it doesn’t require any complex programming or third-party technologies. Also, it can be refreshed easily later on.

  1. Go to the Data ribbon, click on “Get Data” on the left, and select “From Folder” in the “From File” sub-menu.
  2. Select the Folder and click on “Open” (not in the screenshot on the right).
  3. You can now see a preview. Click on “Transform Data”.
  1. Remove the first column “Content” (right-click on the heading and click on “Remove”).
  2. If you want to see more file attributes than shown already in the preview, click on the small arrows of the “Attributes” column and select the attributes.
  3. Click on Close & Load.

Recommendation: Use this method if you to have lots of file properties. It can later on easily be refreshed.

The Excel add-in Professor Excel Tools offers a function to easily insert directories. It regards subfolders and can insert various file properties:

  • Links to files on the drive
  • File path
  • Date and time last saved
  • Date and time created
  • File size
  • File type

You can further specify, where the directory should be created.

Using the “Get Directory” function is very simple:

  1. Click on the Directory button on the Professor Excel ribbon.
  2. Select all the file properties you’d like to show and the location, where the directory table should be placed in your Excel file.
  3. Click on “Select folder and start”. Then, choose the folder and proceed with ok.

That’s it. Please feel free to download Professor Excel Tools here.

Recommendation: Use this method if you accept third-party add-ins within Excel. If you do, it’s quite convenient and fast.

This function is included in our Excel Add-In ‘Professor Excel Tools’

(No sign-up, download starts directly)

More than 35,000 users can’t be wrong.

As you can see in the following description, using PowerShell takes quite a lot of steps. It might be useful, though, if you have very large folder structures. Otherwise, try to use a different method.

Open PowerShell and write the directory into a text file

  1. Navigate to the folder which you want to have the file list from. Hold down the Shift key on the keyboard and right-click on it (if you don’t hold down the Shift key, the option of “Open PowerShell window here” is not available).
  2. Click on “Open PowerShell window here”.
  3. Copy and paste the following code and press enter afterwards:

Import text file into Excel

Open Microsoft Excel.

  1. Open the Text Import Wizard: Go to the Data ribbon, click on “Get Data” on the left, then on “Legacy Wizards” and then on “From Text (Legacy)”. If this option is not available, you can activate it within the Excel settings (check this article for more information).
  2. Select the file filelist.txt from your folder. In step 3 above it was created within your target folder.

Follow the import steps of the Text Import Wizard on the screen:

  1. In the first step of three, make sure that “Fixed width” is selected. Click on Next.
  2. In the lower part of the window, Excel shows a preview of your import. Check here, if the column separators are set correctly: You can move the vertical lines if necessary or add more by clicking on the respective number in the heading of the preview. Then click on Next and in the third step Next again. After that finish the Text Import Wizard by selecting the location where the file list should be placed.
  3. As you can see in number 8, the file list is inserted, but has some disadvantages: Directory paths are cut, each subfolder has its own block, and so on.

In a nutshell: This method of creating file lists within Microsoft Excel via PowerShell is complex and the results aren’t as good as in the other methods.

Recommendation: Try to avoid this method.

Do you want to boost your productivity in Excel?

Get the Professor Excel ribbon!

Add more than 120 great features to Excel!

Method 7: Let a VBA Macro loop through the files

The following VBA code creates a list of all files in a folder. The list will be placed on the currently active worksheet, starting from cell A1. Please make sure that you don’t override anything here.

Here is how to use the VBA-Code. If you need more help of how to use VBA macros, please refer to this article.

  1. Copy the VBA code from above.
  2. Open the VBA editor by pressing Alt + F11 on the keyboard.
  3. Insert a new module: Right-click on the active workbook name on the left.
  4. Go to “Insert” and click on “Module”.
  1. Paste the code by pressing Ctrl + V on the keyboard.
  2. Replace Your folder path with the path from your own folder.
  3. Click on start in the VBA editor.

Download

Please feel free to download all examples from above in this comprehensive Excel workbook. Each method is located on a different worksheet. Just click here and the download starts.

Источник

You probably don’t need this every day: But once a file you might want to have a list of all files within a folder or directory in Excel. The good thing: There are many methods available. If you Google it, you will find a lot of different methods to create a file list in Excel. But unfortunately, all of them have advantages and disadvantages – which you usually only find out after trying them. That’s the reason for this article: You won’t only learn each method step by step: You will rather find an overview comparing all the advantages and disadvantages of each method. After seeing this, you don’t need to start extensive trials and errors. Much better: You can easily select the method that works best for you!

Summary

Method 1:
Copy & Paste on Mac
Method 2:
Named function
Method 3:
Internet browser
Method 4:
PowerQuery
Method 5:
Excel-Add-In
Method 6:
Windows PowerShell
Method 7:
VBA Macro
Short description Copy and paste from the Mac Finder. Use a function in a named range to insert a file list. Open folder with a web browser and copy the file list. Use PowerQuery to insert a directory. Let an Excel add-in do the work for you. Use the Windows built-in PowerShell feature. Use a VBA Macro to insert a file list.
Ease of use
Operating system Mac Windows Windows / Mac Windows / Mac Windows Windows Windows
Include subfolders
and files
No No No Yes Yes Yes (Yes) (depends on the VBA macro)
File information available File names File names File names, file links (not working properly), file size, date modified Folder path, name
extension, date accessed, date modified, date created
More attributes:

Content type, kind, size, ReadOnly, hidden, S
system, directory, archive, device, normal, temporary, SparseFile, ReparsePoint, compressed, offline, NotContentIndexed, encrypted, ChangeTime, SymbolicLink, MountPoint

Links to files on the drive, file path, date and time last saved, date and time created, file size, file type File name, file path, date and time last saved, file size Depends on the VBA macro
Technology Mac Finder Named function in Excel Internet browser PowerQuery Excel Add-In PowerShell, Text Import Wizard VBA
Comment Fast but with limited options. Only shows files, no folders. File links not working in our test; not working with all internet browsers (tested with Google Chrome and working). Elegant and uses built-in functions. Convenient, fast and many options. Results not good, difficult process; performs well on large file structures, though. Modifying the macro rather for advanced users.
Link Click here Click here Click here Click here Click here Click here Click here

Method 1: Simply copy and paste from Mac Finder to Excel

File list on a Mac: Just copy and paste from Finder to Excel.
File list on a Mac: Just copy and paste from Finder to Excel.

This first method works on a Mac only: Just select all files in a Finder window and press copy (Command + C on the keyboard). Next, switch to Excel and paste the list: Press Command + V on the keyboard.

The advantage of this method is that it’s very easy and fast. Unfortunately, you don’t have any further options than just pasting the file names. That means you can’t insert data of subfolders or file properties.

Recommendation: Use this if you need a quick file list on the Mac – without any further information.

Method 2: Insert a file list with built-in Excel functions using “Named Ranges”

The second method is actually quite elegant: Use built-in Excel functions to insert a file list in Excel. It is built on advanced functions, such as an Excel function within a named range. But following these steps should be quite straight-forward.

Set up the named range

Create a list of all files with Excel built-in features. Here: A function within a named range.
Create a list of all files with Excel built-in features. Here: A function within a named range.
  1. Choose a cell in which you later write the folder path. In this case, it’s cell C4.
  2. Click on “Defined Name” on the Formulas ribbon.
  3. Give a name for the cell containing the folder path (here: “Folder_Path”)
  4. In the “Refers to” field, type: =files(linktopathcell) (replace “linktopathcell” with your cell reference – in this case “Method_2!$C$4”).
  5. Confirm with OK.

Use the named range in Excel functions

Copy the folder path from Windows Explorer.
Copy the folder path from Windows Explorer.
  1. Go to the Windows Explorer and copy the folder path.
As the last step, set up a INDEX formula that pulls the file names into cells.
As the last step, set up a INDEX formula that pulls the file names into cells.
  1. Paste the folder link into the folder path cell (the cell you have set as the named range in step 1 above). Add one of the following endings:
    • If you want to include all files – no matter which file type – in your list, add *
    • For listing only Excel files, add *.xls*
    • If you want to see all files ending on “.xlsx”, add *.xlsx
  2. As the last step, enter an INDEX function for compiling the list (here in cell B7):
    =INDEX(Folder_Path,ROW(B1))
    Folder_Path should be the same name that you have given in step 3 above. The ROW function should refer to any cell in the first row (for example to B1). That means, this argument could also be A1, C1, etc.
    As the last step: Copy the INDEX function down until you see the first #REF error. #REF means in this case that there are no more files in your folder. If you like, you could wrap the IFERROR function around in order to mitigate the error.

Recommendation: Use this if you only need a list of files (no subfolders) that dynamically updates itself.

Method 3: Use an internet browser to quickly copy and paste a file list to Excel

I must say, I like this idea because it’s almost as fast as our method number 1 above: Open a folder in a webbrowser and then copy & paste the list to Excel.

Copy the folder path from Windows Explorer.
Copy the folder path from Windows Explorer.
  1. Copy the folder path from the Windows Explorer like on the screenshot or Mac Finder (for Mac: open file Info (right-click on folder and then on “Get Info”. Select and copy link from “Where” section).
Open the folder path with a web browser. Then copy and paste the file list into Excel.
Open the folder path with a web browser. Then copy and paste the file list into Excel.
  1. Open a browser, for example Google Chrome (should be working with most other browsers as well). Paste the previously copied link into the address field.
  2. Copy the table of files.
  3. Open Excel and paste the file list.

One comment to this methods: The links (which are also created) usually won’t work in Excel.

Recommendation: Use this if you quickly need a file list (without subfolders), including some file properties such as file size and date last saved.

Method 4: Create a file list with PowerQuery

PowerQuery can also create lists of all files and folders, including subfolders.
PowerQuery can also create lists of all files and folders, including subfolders.

The next method is also among my favorites: It uses PowerQuery and comes with the advantages that it doesn’t require any complex programming or third-party technologies. Also, it can be refreshed easily later on.

  1. Go to the Data ribbon, click on “Get Data” on the left, and select “From Folder” in the “From File” sub-menu.
  2. Select the Folder and click on “Open” (not in the screenshot on the right).
  3. You can now see a preview. Click on “Transform Data”.
Above that, PowerQuery allows to insert various file attributes.
Besides that, PowerQuery allows to insert various file attributes.
  1. Remove the first column “Content” (right-click on the heading and click on “Remove”).
  2. If you want to see more file attributes than shown already in the preview, click on the small arrows of the “Attributes” column and select the attributes.
  3. Click on Close & Load.

Recommendation: Use this method if you to have lots of file properties. It can later on easily be refreshed.

The Excel add-in Professor Excel Tools offers a function to easily insert directories. It regards subfolders and can insert various file properties:

  • Links to files on the drive
  • File path
  • Date and time last saved
  • Date and time created
  • File size
  • File type
The Excel add-in Professor Excel Tools provides a function to insert a directory in Excel.
The Excel add-in Professor Excel Tools provides a function to insert a directory in Excel.

You can further specify, where the directory should be created.

Using the “Get Directory” function is very simple:

  1. Click on the Directory button on the Professor Excel ribbon.
  2. Select all the file properties you’d like to show and the location, where the directory table should be placed in your Excel file.
  3. Click on “Select folder and start”. Then, choose the folder and proceed with ok.

That’s it. Please feel free to download Professor Excel Tools here.

Recommendation: Use this method if you accept third-party add-ins within Excel. If you do, it’s quite convenient and fast.


Professor Excel Tools Box

This function is included in our Excel Add-In ‘Professor Excel Tools’

(No sign-up, download starts directly)


As you can see in the following description, using PowerShell takes quite a lot of steps. It might be useful, though, if you have very large folder structures. Otherwise, try to use a different method.

Open PowerShell and write the directory into a text file

The PowerShell method is very complex. First open the folder in PowerShell and paste a line of code.
The PowerShell method is very complex. First open the folder in PowerShell and paste a line of code.
  1. Navigate to the folder which you want to have the file list from. Hold down the Shift key on the keyboard and right-click on it (if you don’t hold down the Shift key, the option of “Open PowerShell window here” is not available).
  2. Click on “Open PowerShell window here”.
  3. Copy and paste the following code and press enter afterwards:
Get-ChildItem -Path $MyInvocation.MyCommand.Path -force -recurse > filelist.txt

Import text file into Excel

Open Microsoft Excel.

Next, import a text file containing the directory into Excel.
Next, import a text file containing the directory into Excel.
  1. Open the Text Import Wizard: Go to the Data ribbon, click on “Get Data” on the left, then on “Legacy Wizards” and then on “From Text (Legacy)”. If this option is not available, you can activate it within the Excel settings (check this article for more information).
  2. Select the file filelist.txt from your folder. In step 3 above it was created within your target folder.
Fine-tune the import so that all files are shown correctly.
Fine-tune the import so that all files are shown correctly.

Follow the import steps of the Text Import Wizard on the screen:

  1. In the first step of three, make sure that “Fixed width” is selected. Click on Next.
  2. In the lower part of the window, Excel shows a preview of your import. Check here, if the column separators are set correctly: You can move the vertical lines if necessary or add more by clicking on the respective number in the heading of the preview. Then click on Next and in the third step Next again. After that finish the Text Import Wizard by selecting the location where the file list should be placed.
  3. As you can see in number 8, the file list is inserted, but has some disadvantages: Directory paths are cut, each subfolder has its own block, and so on.

In a nutshell: This method of creating file lists within Microsoft Excel via PowerShell is complex and the results aren’t as good as in the other methods.

Recommendation: Try to avoid this method.


Do you want to boost your productivity in Excel?

Get the Professor Excel ribbon!

Add more than 120 great features to Excel!


Method 7: Let a VBA Macro loop through the files

The following VBA code creates a list of all files in a folder. The list will be placed on the currently active worksheet, starting from cell A1. Please make sure that you don’t override anything here.

Sub InsertFileList()

Dim objFileSystemObject As Object, objFolder As Object, objFile As Object, i As Integer

Set objFileSystemObject = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFileSystemObject.GetFolder("Your folder path")

For Each objFile In objFolder.Files
    i = i + 1
    ActiveSheet.Cells(i, 1) = objFile.Name
Next

End Sub
Insert a new module in VBA.
Insert a new module in VBA.

Here is how to use the VBA-Code. If you need more help of how to use VBA macros, please refer to this article.

  1. Copy the VBA code from above.
  2. Open the VBA editor by pressing Alt + F11 on the keyboard.
  3. Insert a new module: Right-click on the active workbook name on the left.
  4. Go to “Insert” and click on “Module”.
Paste the code sample from above, replace "Your folder path" and run the macro.
Paste the code sample from above, replace “Your folder path” and run the macro.
  1. Paste the code by pressing Ctrl + V on the keyboard.
  2. Replace Your folder path with the path from your own folder.
  3. Click on start in the VBA editor.

Download

download, arrow

Please feel free to download all examples from above in this comprehensive Excel workbook. Each method is located on a different worksheet. Just click here and the download starts.

Image by Pexels from Pixabay

Maintaining an Excel spreadsheet of computer files can help you keep track of important business documents or images. Unfortunately, Microsoft Excel doesn’t include a one-step method for importing a file list from Windows Explorer, but Windows 7 offers an easy workaround. Using the Command Prompt, you can tell Windows to output a text document containing a directory list. This text document can then be imported into Excel and modified just like any other spreadsheet.

  1. Press «Win-E» to open Windows Explorer and locate the folder for which you need a file list.

  2. Hold the «Shift» key, right-click the folder and select «Open Command Window Here.» This only works with folders, not libraries. Libraries point to a specific folder, so select the folder located under the library icon. If the library points to a drive, right-click the drive letter from the folder tree.

  3. Type «dir /b > dirlist.txt» without quotes and press «Enter.» This creates a list containing file names only. To include file sizes and dates, type «dir > dirlist.txt» instead. To also include files in sub-directories, type «dir /b /s > dirlist.txt» to create a list of files with the full directory structure name, such as «C:foldersubdirectoryfile.txt.»

  4. Open Microsoft Excel and press «Ctrl-O» to bring up the Open dialog window.

  5. Navigate into the folder containing the files. Click the file type drop-down menu and select «Text Files (.prn,.txt,*.cvs).» Double-click «dirlist.txt» to open it.

  6. Click «Finish» in the Text Import Wizard window to use the default options and import the directory list into Excel.

Listing the files in a folder is one of the activities which cannot be achieved using normal Excel formulas.  I could tell you to turn to VBA macros or PowerQuery, but then any non-VBA and non-PowerQuery users would close this post instantly.  But wait!  Back away from the close button, there is another option.

For listing files in a folder we can also use a little-known feature from Excel version 4, which still works today, the FILES function.

If you search through the list of Excel functions, FILES is not listed.  The FILES function is based on an old Excel feature, which has to be applied in a special way.  The instructions below will show you step-by-step how to use it.

Create a named range for the FILES function

The first step is to create a named range, which contains the FILES function.  Within the Excel Ribbon click Formulas -> Define Name

FILES - Define Name Ribbon

Within the New Name window set the following criteria:

  • Name: listFiles
    Can be any name you wish, but for our example we will be using listFiles.
  • Refers to: =FILES(Sheet1!$A$1)
    Sheet1!$A$1 is the sheet and cell reference containing the name of the folder from which the files are to be listed.

FILES - New Name listFiles

Click OK to close the New Name window.

Apply the function to list files

The second step is to set-up the worksheet to use the named range.

In Cell A1 (or whichever cell reference used in the Refers to box) enter the folder path from which to list the files, followed by an Asterisk ( * ).  The Asterisk is the wildcard character to find any text, so it will list all the files in the folder.

Select the cell in which to start the list of files (Cell A3 in the screenshot below), enter the following formula.

=INDEX(listFiles,1)

FILES formula - first result

The result of the function will be the name of the first file in the folder.

To retrieve the second file from the folder enter the following formula

=INDEX(listFiles,2)

It would be painful to change the file reference number within each formula individually, especially if there are hundreds of files.  The good news is, we can use another formula to calculate the reference number automatically.

=INDEX(listFiles,ROW()-ROW(A$2))

The ROW() function is used to retrieve the row number of a cell reference.  When used without a cell reference, it returns the row number of the cell in which the function is used.  When used with a cell reference it returns the row number of that cell.  Using the ROWS function, it is possible to create a sequential list of numbers starting at 1, and increasing by 1 for each cell the formula is copied into.

If the formula is copied down further than the number of files in the folder, it will return a #REF! error.

FILES with errors

Finally, wrap the formula within an IFERROR function to return a blank cell, rather than an error.

=IFERROR(INDEX(listFiles,ROW()-ROW(A$2)),"")

FILES function IFERROR

Listing specific types of files

The FILES function does not just list Excel files; it lists all file types; pdf, csv, mp3, zip, any file type you can think of.  By extending the use of wildcards within the file path it is possible to restrict the list to specific file types, or to specific file names.

The screenshot below shows how to return only files with “pdf” as the last three characters of the file name.

FILES with wildcards

The wildcards which can be applied are:

  • Question mark ( ? ) – Can take the place of any single character.
  • Asterisk ( * ) – Represents any number of characters
  • Tilde ( ~ ) – Used as an escape character to search for an asterisk or question mark within the file name, rather than as a wildcard.

The screenshot below shows how to return only files with the name of “New York.“, followed by exactly three characters.

FILES with wildcards 2

Advanced uses for the FILES named range

Below are some ideas of how else you could use the FILES function.

Count the number of files

The named range created works like any other named range.  However, rather than containing cells, it contains values.  Therefore, if you want to calculate the number of files within the folder, or which meet the wildcard pattern use the following formula:

=COUNTA(listFiles)

Create hyperlinks to the files

Wouldn’t it be great to click on the file name to open it automatically?  Well . . . just add in the HYPERLINK function and you can.

FILES with hyperlinks

The formula in Cell A3 is:

=IFERROR(HYPERLINK(LEFT($A$1,LEN($A$1)-1)&INDEX(listFiles,ROW()-ROW(A$2)),
INDEX(listFiles,ROW()-ROW(A$2))),"")

Check if a specific file exists within a folder

It isn’t necessary to list all the files to find out if a file exists within the folder.  The MATCH function will return the position of the file within the folder.

FILES with MATCH function

The formula in cell B3 is:

=MATCH(A3,listFiles,0)

In our example, a file which contains the text “New Yor*” exists, as the 7th file, therefore a 7 is returned.  Cell B4 displays the #N/A error because “Seattle” does not exist in the folder.

Find the name of the next or previous file

The files returned are in alphabetical order, therefore it is possible to find the next or previous file using the INDEX / MATCH combination.

FILES find the next or previous file

The next file after “Denver.xlsx” is “New York.pdf“. The formula in Cell B3 is:

=INDEX(listFiles,MATCH(A3,listFiles,0)+1)

Retrieve values from each file with INDIRECT

The INDIRECT function can construct a cell reference using text strings.  Having retrieved the list of files in a folder, it would be possible to obtain values from those files.

FILES with INDIRECT

The formula in Cell B3 is:

=INDIRECT("'"&LEFT($A$1,LEN($A$1)-1)&"["&A3&"]Sheet1'!$A$1")

For INDIRECT to calculate correctly the file does need to be open, so this may be a significant flaw in this option.

Usage notes

When working with the FILES function there are a few things to be aware of:

  • The file path and file name is not case sensitive
  • Files are returned in alphabetical order
  • Folders and hidden files are not returned by the function
  • The workbook must be saved as a “.xlsm” file format

Further reading

There are variety of other Excel 4 functions available which still work in Excel. Check out this post to find out how to apply them and download the Excel 4 Macro functions reference guide.

If you decide to use a VBA method, check out this post.


Headshot Round

About the author

Hey, I’m Mark, and I run Excel Off The Grid.

My parents tell me that at the age of 7 I declared I was going to become a qualified accountant. I was either psychic or had no imagination, as that is exactly what happened. However, it wasn’t until I was 35 that my journey really began.

In 2015, I started a new job, for which I was regularly working after 10pm. As a result, I rarely saw my children during the week. So, I started searching for the secrets to automating Excel. I discovered that by building a small number of simple tools, I could combine them together in different ways to automate nearly all my regular tasks. This meant I could work less hours (and I got pay raises!). Today, I teach these techniques to other professionals in our training program so they too can spend less time at work (and more time with their children and doing the things they love).


Do you need help adapting this post to your needs?

I’m guessing the examples in this post don’t exactly match your situation. We all use Excel differently, so it’s impossible to write a post that will meet everybody’s needs. By taking the time to understand the techniques and principles in this post (and elsewhere on this site), you should be able to adapt it to your needs.

But, if you’re still struggling you should:

  1. Read other blogs, or watch YouTube videos on the same topic. You will benefit much more by discovering your own solutions.
  2. Ask the ‘Excel Ninja’ in your office. It’s amazing what things other people know.
  3. Ask a question in a forum like Mr Excel, or the Microsoft Answers Community. Remember, the people on these forums are generally giving their time for free. So take care to craft your question, make sure it’s clear and concise.  List all the things you’ve tried, and provide screenshots, code segments and example workbooks.
  4. Use Excel Rescue, who are my consultancy partner. They help by providing solutions to smaller Excel problems.

What next?
Don’t go yet, there is plenty more to learn on Excel Off The Grid.  Check out the latest posts:

Download PC Repair Tool to quickly find & fix Windows errors automatically

In this post, we will see how to get a list of files in a folder into Excel. We will show you how to use Excel to view Files and Folder details in Windows, by importing all files and folders details into Microsoft Excel to keep track of file size, file type, and last modified date.

We have many files and folders in our Windows PC and we may delete or add more files and folders frequently. There could be some folders and files which are very important to us and someone might edit them without our notice. But, we cannot keep on looking at each and every folder and file to know which one was edited. If it was a modification of a file or folder, we can sort them by using ‘Last modified’ and we can get to know which were modified recently.

My files and folders

But, what if some of the files and folders were deleted from that directory? We would not be in a position to keep track of what was exactly deleted. But, you can use Excel to view files and folder details of directory which would be helpful to you to know at least the list of files and folders that were deleted.

How to get a list of files in a folder into Excel

Import and get a list of filenames into an Excel sheet

If you use Microsoft Excel to import all details of files and folders into Excel, it will help you keep track of last modified date and time, file types, list of files, files size and many more regularly. To do this, follow these simple steps.

Move to the directory or folder on Windows File Explorer which you want to keep track of. Here, I want to keep track of my files and folders of Documents folder. Copy the path of that directory.

Directory path

Now, open any web browser of your choice and paste the copied path (Path of the folder you just copied in the previous step) in the address bar of the browser. I used Google Chrome here. Just prefix the URL by file:///and the content will be shown as the web page.

Contents of my directory

To save this web page as the offline copy, press CTRL+S or right-click on the web page and select “Save Page As”. Select the destination, give it a name, and save the webpage.

save offline webpage

Now, via Windows Explorer go the location you saved the offline webpage and copy the path. The, open the Excel sheet and tap on the Data tab and click on From Web. It opens up the Window and in the Address bar paste the copied path and click the “Go” button. It will load all the contents of the webpage.

Import from web

It shows you the yellow boxes with arrows and it will allows you to select the required frame. You can find here that I selected the part I want.

Select the frame

Once done with these steps, now click on Import button and you see that all the files and folders details are imported to your Excel sheet in no time. You can see that the data is shown in the columns and gives us a clear idea of every detail.

import files and folders details to excel

Conclusion

As we are engaged most of the time, in organizing files and folders, it is advisable to import files and folders details into Excel. This would be helpful if any of your file or folder was to get deleted. The data in the Excel sheet does not refresh, so we need to import the data regularly.

You can use this method when to not only keep track of file changes but also filenames.

Ezoic

Sridhar is a Software Engineer who loves to stay updated with developments in the world of technology. He is fond of writing everything related to Internet, Computers and Mobile and Desktop Operating Systems.

Понравилась статья? Поделить с друзьями:
  • File is not a recognized excel file python
  • File input accept excel
  • File information in excel
  • File in use word document
  • File formats supported by excel