# How to create a batch file to read size of file on specific folder path



## sky2013 (Jul 16, 2013)

Dear All,

I need to create a batch file which can read the size of file(e.g. 1kb, 2kb...etc) from specific folder and detect 0kb file and convert it to text file (showing 0kb file size) with alarm.

I am not really sure how to write command for this batch file. Please help :-(


----------



## peterh40 (Apr 15, 2007)

Here's an example using Powershell:

# Test file size
Param($myfile)
$file = Get-Item $myfile
$size = $file.Length
If ($size -eq 0 ) {
write-host "File $myfile is size zero!"
[System.Media.SystemSounds]::Beep.Play()
}


----------



## sky2013 (Jul 16, 2013)

I only can use batch file application... I can't install powershell application because no internet connection.


----------



## peterh40 (Apr 15, 2007)

TRy this VBS file, which can be run on any PC:

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("C:\Myfile.txt")

If objFile.Size = 0 Then
Wscript.Echo "The file is empty."
Wscript.Echo CHR(7)
End If


----------



## Squashman (Apr 4, 2003)

So you are still on XP because I believe PS is installed by default on Vista and 7.

You can get a files size one of two ways using a For loop in batch. 

I am on my phone right now but if you read the help for the FOR cmd you should see the modifier that shows the files size.


----------



## sky2013 (Jul 16, 2013)

Thanks for the VBS. Is this only applicable if we already have a text document? What i need is, e.g. folder from *D:\DVB Bitmap Encoder\MYS\Subs In* is *converted* to *.txt* file if 0KB file size is detected with an alarm. I try to learn through Youtube but it is still confusing. Sorry :-(


----------



## Squashman (Apr 4, 2003)

```
for %%G in ("C:\myfile.txt") do IF "%%~zG"=="0" echo ALARM
```


----------



## sky2013 (Jul 16, 2013)

Can you show me a simple program how the script that you provided works? I have tried but i could not get the result. Somehow i have managed to create VBS to find 0kb files in a Directory.Any idea how i can create a batch file which will identify 0 in the text file and immediately trigger alarm to alert people. It also must delete the generated text file using VBS every 10 hours.


----------



## sky2013 (Jul 16, 2013)

Any answer for this?


----------

