Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: how to find the file is empty or not?  (Read 2135 times)

0 Members and 1 Guest are viewing this topic.

ankush

    Topic Starter


    Rookie

    how to find the file is empty or not?
    « on: May 19, 2008, 03:43:48 PM »
    Hi,

    i will receive lot of files every day, is there any way, with which i can find the empty files or the files with less than 5 records.

    thank you

    ghostdog74



      Specialist

      Thanked: 27
      Re: how to find the file is empty or not?
      « Reply #1 on: May 19, 2008, 10:04:22 PM »
      vbscript
      Code: [Select]
      Set objFSO = CreateObject("Scripting.FileSystemObject")
      strMyFile = "c:\test\new.txt"
      i=0
      Set objFS = objFSO.GetFile(strMyFile)
      If objFS.Size = 0 Then
      WScript.Echo "0 size file: " & objFSO.GetFile(strMyFile).Name
      Else
          Set objFS = objFSO.OpenTextFile(strMyFile)
          Do Until objFS.AtEndOfLine
          objFS.ReadLine
      i=i+1
      Loop
      WScript.Echo i
      If i < 5 Then
      WScript.Echo "File: " & strMyfile & " has less than 5 records "
      End If
      End If


      save as script.vbs and on command line
      Code: [Select]
      c:\test> cscript /nologo script.vbs

      ankush

        Topic Starter


        Rookie

        Re: how to find the file is empty or not?
        « Reply #2 on: May 20, 2008, 08:36:50 AM »
        Hi,
        this code is super, it works very good, but can you help in adding few more things to it, like can i give the directory path and work on all the file in the directory, and how can it get the email of this result.

        thank you

        ankush

          Topic Starter


          Rookie

          Re: how to find the file is empty or not?
          « Reply #3 on: May 21, 2008, 09:31:55 AM »
          Hi,

          i will receive lot of files every day, is there any way, with which i can find the empty files or the files with less than 5 records.

          thank you