Jump to content

How many files in a folder?


Recommended Posts

Is there any way to find out how many files are in folders? What I want to do is search for all my music folders that have one file in them and combine all the folders. I can not figure out a way to find out what folders only have one song tho. Anybody have ideas?

Link to comment
Share on other sites


To use the line above, open a cmd prompt and navigate to the directory you are wishing to count files in, then enter it at the prompt!

The following batch file will currently show 'on screen' all of your directories containing only one file.

onefile.cmd

@echo off
for /d /r "%~1" %%a in (*) do (
 for /f "tokens=1" %%b in ('dir "%%a" /a-d 2^>nul ^| find "File(s)"') do if '%%b' equ '1' call :dostuff "%%~a"
)
goto :eof

:dostuff
echo %1
goto :eof

To use this one open a cmd prompt and navigate to the directory containing this batch file. At the prompt type

onefile "Drive:\Folder Path"

where "Drive:\Folder Path" is the location of the directory you wish to 'count files' in. (you only need the quotes if there is a space in the folder path)

If you can explain 'combine all folders' I may be able to help with the rest, otherwise if you wish to do it yourself, just replace the line echo %1, under the :dostuff label with your new commands. Just as a note, the qualifying directories within this section will remain named as %1

Link to comment
Share on other sites

I have updated the code in my above reply to better reflect your requirements

Also, just as a note, bear in mind that the directories may contain hidden thumbs.db or desktop.ini files which could bring unpredictable results.

Run the batch as it is for now and check the results on screen for such anomalies first!

Link to comment
Share on other sites

Thanks. I think I had too many folders for that script to work. I get the error "the full path of is too long." I downloaded a program called treesize. That tells me how big the folders are so I guess that will do. Thanks for trying guys! I never even knew the command "for" was allowed thought it was some vb script or something lol.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...