Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I have an windows xp version of Batch files for the person asking this qustion if that helps.
Ok, I know you can creat a batch that tells you the file count. But Is it possible to make a batch file that creats a folder and in that folder, displays (in a txt file) the file count and size of a folder (of users choose).
Eg, I had a folder that had 20 pictures and 10 Mp3 files. Can a batch file display the count of files in the folder (which would be 30) and the total size of the folder ( all the files in the folder).
Added to this, instead of the batch file being fix to one folder (eg c:\test) but make it so that you can type in the path of the folder when the batch file opens?
I hope this is not to much to ask of you? (whoever is aswering ) :)

well, i have some questions.
You want the the count and size to be written in a file. Let us say this file is FileCountandDirSize.txt
do you want the total size including this file and size or excluding this file and size of it?
It gets complicated if this file need to be included and the size need to be accurate to the bytes.
Do you want the total size including sub folders inside a directory?
This batch file counts total files and their total size and prints it to screen.
Can easily be modified to print to a file.@echo off setlocal enabledelayedExpansion set dir=%~1 set tz= set count= if "%dir%"=="" set dir=. for %%A in ("%dir%\*") do ( set curfilesize=%%~zA set /a tz=tz + !curfilesize! set /a count+=1 echo count=!count! ) echo There are !count! files in directory "%dir%" amounting to %tz% bytes.--
Holla.

@echo off & setLocal EnableDelayedExpansion
if %1'==' echo which directory? && goto :eof
echo %1 has: >> my.txt
dir %1 | find "File(s)" >> my.txt
=====================================
If at first you don't succeed, you're about average.M2

@ Holla,
No it would be too confusing to include the FileCountandDirSize.txt file.
And yes all subfolders inside a directory is what i need.
Is it possible to just type in an Address of a folder (the one i want "scanned") and have it creat the file in the same folder as the batch file?
Eg My batch file will be in C:\test and the folder i want scanned in F:\Folder. When the batch is run a .txt (FileCountandDirSize.txt) will be created in C:\test.
@ Mechanix2Go
It didnt work, unless i am doing something wrong. it just pops up for about one sec then dissappears... with no change to anything, well anything that i can see.

"pops up" my foot.
Run it from a prompt.
=====================================
If at first you don't succeed, you're about average.M2

It does! lol
This is what i am doing (knowing that i am not that only a begginer).
Copy - paste -save as File.batIs there something i am meant to do before running?
How would i run it from cmd prompt? i know how to get cmd run but yeah...

start > run > cmd
Then CD to the directiry where you put file.bat.
type file [enter]
=====================================
If at first you don't succeed, you're about average.M2

As always' M2's solution is superior.
My method breaks when the total size exceeds 2147483647.
Having taken this into consideration, the following takes care of all u asked for, if I am right...@echo off set dir=%~1 if "%dir%"=="" echo Usage: & echo %0 "c:\Directory" & Echo Using current directory if "%dir%"=="" set dir=. for /f "tokens=1*" %%a in ('dir /s/w "%dir%" ^| find "File(s)"') do set tz=%%a %%b echo %tz% > "%dir%\FileCountAndTotalSize.txt"--
Holla.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |