Read file size and echo to file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Matt20687
Posts: 54
Joined: 02 May 2012 14:42

Read file size and echo to file?

#1 Post by Matt20687 » 02 Feb 2013 15:55

Hello,

I am about to start a project and need to do some analysis work before starting. Basically what i need to do is to create a batch file that will check a folder that has multiple files coming in and out of it (downloading/uploading), it will be run every minute for 24 hours and will create a .txt file with each of the files in the folder size. I am not expecting any of the files to be any larger than 2meg.

Over the 24 hour period i need to have multiple logs with every files size logged. I am looking for a minimum file size that comes into this folder.

I have created a script that at the moment creates a time stamped .txt that has the amount of files in the folder (this is not required within the .txt as it is in the file name)

Code: Select all

    @ECHO OFF
   
    SETLOCAL
    SETLOCAL ENABLEDELAYEDEXPANSION
    set site=Tnton
    set gn=NH
   
   
    :: Create date and timestamp for email
   
   
    for /f "tokens=1-8 delims=.:/-, " %%i in ('echo exit^|cmd /q /k"prompt $D $T"') do (
       for /f "tokens=2-4 delims=/-,() skip=1" %%a in ('echo.^|date') do (
    set dow=%%i
    set mm=%%j
    set dd=%%i
    set yy=%%k
    set hh=%%l
    set min=%%m
    set sec=%%o
    set hsec=%%p
    )
    )
   
    :: ensure that hour is always 2 digits
   
    if %hh%==0 set hh=00
    if %hh%==1 set hh=01
    if %hh%==2 set hh=02
    if %hh%==3 set hh=03
    if %hh%==4 set hh=04
    if %hh%==5 set hh=05
    if %hh%==6 set hh=06
    if %hh%==7 set hh=07
    if %hh%==8 set hh=08
    if %hh%==9 set hh=09
   
   
    :: Assign timeStamp
    :: Add the date and time parameters as necessary - " yy-mm-dd-dow-min-sec-hsec "
   
    set timeStamp=%yy%%mm%%dd%_%hh%-%min%
       
    SET count=0
    for %%o IN (C:\\*.txt) DO (
          echo %%o
          SET /A count=count + 1
    )

:: Create filename
   
    set fn=%count%--FileLogs--%site%-%gn%-%timestamp%.txt
   
    echo %count% >> %fn%


    ENDLOCAL ENABLEDELAYEDEXPANSION
    ENDLOCAL

pause > nul

abc0502
Posts: 1007
Joined: 26 Oct 2011 22:38
Location: Egypt

Re: Read file size and echo to file?

#2 Post by abc0502 » 02 Feb 2013 18:46

Do you mean each txt file will represent a minute,
And each one of these txt file will contain all the file names along with it's size that existed at this minute ?

Also, can you post the way the txt files will look like ?

I am looking for a minimum file size that comes into this folder.
can you explain more.
you will have about 720 txt file every day, so do you need to search in all of then for the smallest file size ?

Post Reply