ADSM-L

Re: Batch script in Windows to create filelist

2006-08-21 15:57:35
Subject: Re: Batch script in Windows to create filelist
From: Andrew Raibeck <storman AT US.IBM DOT COM>
To: ADSM-L AT VM.MARIST DOT EDU
Date: Mon, 21 Aug 2006 13:55:55 -0600
Standard command line commands are insufficient, so VBScript would be the
answer. I'm not overly familiar with VBScript, but a couple of hours or so
with a reference on Windows scripting and some searches at
http://msdn.microsoft.com allowed me to come up with the following:

==========================================================
' (c) Copyright by IBM Corporation 2006. All Rights Reserved.

' makefilelist.vbs

' This script takes three arguments:

'   - The fully-qualified directory name to scan
'   - The maximum number of days between now and the time the file was
'     last modified for which the file will be flagged
'   - The name of the output file that contains the resulting file list

' This code has not been through any formal testing, and is not
' warranted by IBM. Use at your own risk.



Const ForWriting = 2
today            = Date
nArgs            = WScript.Arguments.Count()

If nArgs = 3 Then
  ' Add 0 to coerce the second argument to a number.
  BuildFileList WScript.Arguments.Item(0), _
                WScript.Arguments.Item(1) + 0, _
                WScript.Arguments.Item(2)
Else
  WScript.Echo "Usage: cscript makefilelist <directory> <days> " & _
               "<output file name>"
End If



Function BuildFileList(dir, days, outFile)
  ' Open the output file.
  Set objFSO = CreateObject("Scripting.FileSystemObject")
  Set objOutFile = objFSO.OpenTextFile(outFile, ForWriting, True)

  ' List the files in the directory specified by the user.
  Set objWMIService = GetObject("winmgmts:" & _
                        "{impersonationLevel=impersonate}!\\." & _
                        "\root\cimv2")
  Set colFiles = objWMIService.ExecQuery("ASSOCIATORS OF " & _
                   "{Win32_Directory.Name='" & dir & _
                   "'} Where ResultClass = CIM_DataFile")

  ' Check each file to see if it has been modified within the last
  ' <days> days.
  For Each objFile in colFiles
    ' WScript.Echo objFile.LastModified & ": " & objFile.Name

    ' Uncomment the line above if you want to see what the LastModified
    ' field looks like. The format is:
    '
    '   yyyyMMddhhmmss.nnnnnn?uuu
    '
    ' yyyy   = year
    ' MM     = month
    ' dd     = day of month
    ' hh     = hour
    ' mm     = minute
    ' ss     = second
    ' nnnnnn = fraction of a second
    ' ?      = '+' or '-' offset from UTC
    ' uuu    = offset from UTC in minutes

    lastMod = Left(objFile.LastModified, 4)   & "-" & _
              Mid(objFile.LastModified, 5, 2) & "-" & _
              Mid(objFile.LastModified, 7, 2)

    diff = DateDiff("d", lastMod, today)

    If diff <= days Then
      objOutFile.WriteLine(objFile.Name)
    End If
  Next

  objOutFile.Close()
End Function
==========================================================

Note that I make no promises that this will do what you need, but at least
it might present a starting point.

Regards,

Andy

Andy Raibeck
IBM Software Group
Tivoli Storage Manager Client Development
Internal Notes e-mail: Andrew Raibeck/Tucson/IBM@IBMUS
Internet e-mail: storman AT us.ibm DOT com

IBM Tivoli Storage Manager support web page:
http://www-306.ibm.com/software/sysmgmt/products/support/IBMTivoliStorageManager.html

The only dumb question is the one that goes unasked.
The command line is your friend.
"Good enough" is the enemy of excellence.

"ADSM: Dist Stor Manager" <ADSM-L AT VM.MARIST DOT EDU> wrote on 08/18/2006
08:07:29 AM:

> Hi,
>
> I need to create a filelist of files that exist in a directory that
> have been updated in the past 7 days and have the list of files
> backed up by TSM. Does anyone know how tis can be done be commands
> native to Windows without requiring any third party software ?
>
> Rich

<Prev in Thread] Current Thread [Next in Thread>