Loop thru folders, grab 0kb file name and export to .txt

  • hi,

    I would like to use the DTS active x script to loop through a folder, check each file, if the file is 0kb, i need to grab the file name and export to .txt file as a list.

    below is my sample code:

    '**********************************************************************

    '  Visual Basic ActiveX Script

    '************************************************************************

    Function Main()

          Set oFS = CreateObject("Scripting.FileSystemObject")

          Set oFolders = oFS.GetFolder("C:\Scripts")

          Set oFiles = oFolders.Files

              For Each oFile In oFiles

                    if oFile.Size = 0 then  

                          MsgBox ("file size is " & oFile.Size)

                    end if

              Next

      Main = DTSTaskExecResult_Success

          Set oFolders = Nothing

          Set oFiles = Nothing

          Set oFile = Nothing

          Set oFS = Nothing

    End Function

    ==========================================================

    instead of showing Msgbox ("file size is " & oFile.Size) , i need to grab the file name which is 0kb to a .txt file.

    how is it possible to do so?

    thanks~

  • You will WRITELINE your oFile to a text file.  There are plenty of sample scripts in VB BOL, and on the internet (to include decent from support.microsoft.com) with textstream, writeline, etc...  with the FSO (filesystemobject)

     



    Good Hunting!

    AJ Ahrens


    webmaster@kritter.net

  • Hi, I would suggest

    http://www.devguru.com/Technologies/vbscript/quickref/vbscript_list.html

    http://www.devguru.com/Technologies/vbscript/quickref/file.html

    as a good online reference site, with examples ...

    I use it all the time, almost as an online manual.

    Happy coding,

    H

  • Msgbox ("File name is " & oFile.Name)

  • Thanks All...

    I will look into the sample code and shall revert to you all back should i have further enquiries.

    Many thanks~

  • use the ofile.type = "text file" and check in the if condition.

     

    if ofile.size=0 and ofile.type="text file"

    This will suffice ur requirement.

     

     

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply