Computing.Net > Forums > Programming > Batch Diagnosics

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch Diagnosics

Reply to Message Icon

Name: rjone187
Date: February 9, 2009 at 20:31:19 Pacific
OS: Windows XP
CPU/Ram: -
Product: Intel / -
Subcategory: Batch
Comment:

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 ) :)



Sponsored Link
Ads by Google

Response Number 1
Name: Holla
Date: February 10, 2009 at 03:20:10 Pacific
Reply:

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.


0

Response Number 2
Name: Mechanix2Go
Date: February 10, 2009 at 04:14:08 Pacific
Reply:

@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


0

Response Number 3
Name: rjone187
Date: February 10, 2009 at 16:41:41 Pacific
Reply:

@ 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.


0

Response Number 4
Name: Mechanix2Go
Date: February 10, 2009 at 19:55:00 Pacific
Reply:

"pops up" my foot.

Run it from a prompt.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 5
Name: rjone187
Date: February 10, 2009 at 20:20:36 Pacific
Reply:

It does! lol

This is what i am doing (knowing that i am not that only a begginer).
Copy - paste -save as File.bat

Is 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...


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: February 10, 2009 at 20:35:32 Pacific
Reply:

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


0

Response Number 7
Name: rjone187
Date: February 10, 2009 at 20:38:48 Pacific
Reply:

Yep, That works. hehe Thanks for the help...


0

Response Number 8
Name: Holla
Date: February 10, 2009 at 22:53:05 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Batch Diagnosics

Batch File Reference Help www.computing.net/answers/programming/batch-file-reference-help/18493.html

Batch file to count a specific character in a www.computing.net/answers/programming/batch-file-to-count-a-specific-character-in-a/19751.html

Collect Antivirus info via batch www.computing.net/answers/programming/collect-antivirus-info-via-batch/20104.html