1.

Solve : Create .Bat file to count files in folder?

Answer»

What do I NEED to create a txt file which lists and counts files in folders. Directory and sub directory

For Example:

c:Test\List of Folders

Folder Name: Number of Files

Folder 1: 32 (files/docs)

Folder 2: 28 (files/docs)

Folder 3: 23 (files/docs)

And a more tricky QUESTION, if the folder contains .docs created by a mailmerge, is it possible to return the number of letters contained within the mailmerge?

I mailmerge would contain multiple individual letters
ECHO OFF
set c=0
:TOP
for /f "tokens=1*" %%a in ('dir /a * /b /s') do (
       call set /a c=%%c%%+1
)
CLS&ECHO %c% Files.






place it in the folder you want a file count in, or place it in your root folder to count all files on your system,  the /a switch includes hidden files and the /s switch includes all sub directorysThanks Diablo

But it doesn't work, the command just sits

would like it to be placed in a txt file tosorry it does work

added pause so i could see

how do i add it to a txt file.

and break it down so it lists the sub-directories with each amountI'm really trying

cmd /c "dir C:\Users\Jbloggs\Desktop\bbs > c:\temp\output.txt"

it returns:

 Volume in drive C is OS
 Volume Serial Number is xxxxxxxx

 Directory of C:\Users\JbloggsDesktop\bbs

08/12/2008  20:01              .
08/12/2008  20:01              ..
08/12/2008  20:26                63 co1.bat
03/12/2008  15:41              test1
03/12/2008  16:48              test2
               1 File(s)             63 bytes
               4 Dir(s)  395,136,864,256 bytes free

How do I tweak it, to read in a more plain english


This may help:

Code: [Select]echo off
setlocal enabledelayedexpansion
set folder=C:\Users\Jbloggs\Desktop\bbs
for /f "tokens=* delims=" %%v in ('dir /a:d /s /b "%folder%"') do (
for /f "tokens=* delims=" %%i in ('dir /a:-d /b "%%v" 2^>^&1') do (
if /i %%i NEQ "File Not Found" call set /a count=%%count%%+1
)
echo %%v: !count! (files/docs^)
set count=0
)

Be sure to set the folder variable correctly.

Good luck.

EDIT: In the interest of accuracy and future readers, the code was modified to correct a syntax error.i think may a bit more difficult than expected

appreciate the help, sidewider. your code works, but i don't need to see the file path and want it to display in txt file

but what i'm after is

a simple display to a txt file

List the directory of folders and sub folders with how much files each contains

ie

Folder 1 = 34
Folder 2 = 23
etc

i'm learning alot for you guys.. thanksA tweak here, a tweak there, soon you have a new variation of the same old song:

Code: [Select]echo off
setlocal enabledelayedexpansion
set folder=C:\Users\Jbloggs\Desktop\bbs
for /f "tokens=* delims=" %%v in ('dir /a:d /s /b "%folder%"') do (
for /f "tokens=* delims=" %%i in ('dir /a:-d /b "%%v" 2^>^&1') do (
if /i %%i NEQ "File Not Found" call set /a count=%%count+1
)
echo %%~nv: !count! >> textfile.txt
set count=0
)

As before, make sure the folder variable is set correctly. For a lack of imagination, the output file is labeled textfile.txt

Quote

And a more tricky question, if the folder contains .docs created by a mailmerge, is it possible to return the number of letters contained within the mailmerge?

What method do you use to split out each letter? Seems like a third party program would be involved. Need more details.

 THANKS Sidewinder

I will have to play around with the code.

With regards to the mailmerge. These are number of letters (.doc) contained within word.

To split I have the start and end of each letter identified with a flag

and Quote
With regards to the mailmerge. These are number of letters (.doc) contained within word.

To split I have the start and end of each letter identified with a flag

<begin> and <end>

For this you'll either need to WRITE an internal Word macro (VBA) or an external script using any of the COM aware script languages (VBScript, JScript, Python, REXX, etc.)

This link may give you some ideas about scripting Word using VBScript.

Good luck.


Discussion

No Comment Found