Advertisement

01.30.2007 at 04:43PM PST, ID: 22142993
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

VBScript to Filter Files by Last Modified Date

Tags: vbscript, date, modified, file, last
I have a VBScript that ive been working with , its shy of what I'd like to accomplish .  I would like to be able to specify in the .ini to only output files last modified after a particular date or not modified within x amount of days.  This sorts them by modified date, and can specify overall age of file inx days.  

I also have an issue with the xml output , I can and have modified the script to output to a txt file successfully. I really need to get this out in a xml format.  Some help is greatly needed as a novice who's brain is cramping and eyes crossing.   See the script and ini  below.

`Contents of DOCSCAN.VBS
-----------------------
'DocScan Report Program
'Scans folders for old files, and generates a report
'Reads a text file for options of folders to scan, file types and age

Const ForReading = 1
Dim aDirs=C:\
Dim aExts
Dim dOptionsDate=01/01/2007
Dim strSortBy
Dim intFileCount
Dim intTotalMB

Const adVarChar = 200
Const adDouble = 5
Const adInteger = 3
Const adDate = 7
Const adCurrency = 6
Const MaxCharacters = 255
strFile="options.ini"
bDebug=False
Dim log

Set oShell = WScript.CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
'set up regular expression to use to filter file types
set oregexp=new regexp
oregexp.global=true
oregexp.ignorecase=true

'read the Options.ini file
readoptions

Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "Path", adVarChar, MaxCharacters
DataList.Fields.Append "Size", adDouble, MaxCharacters
DataList.Fields.Append "Age", adInteger, MaxCharacters
DataList.Fields.Append "LastMod", adDate, MaxCharacters
DataList.Open

baseDate = Now - dOptionsDate

'loop through all folder to read files
for i=lbound(aDirs) to ubound(aDirs)
  on error resume next
  Set fl = fso.GetFolder(aDirs(i))
  If err.number *{> 0 then
    Err.Clear
  Else
    'set up regexp search pattern based on extensions from options file
    'pattern should appear something like "^[w- .]+.(com|pif|vbs|vbe|exe|bat|cmd)$"
    strpattern="^[w- .]+.("
    for j=lbound(aExts) to ubound(aExts)
       strpattern = strpattern & (aExts(j))
       if j *{> ubound(aExts) then strpattern = strpattern & "|"
    next
    strpattern = strpattern & ")$"
    if bDebug then wscript.echo strpattern
    oregexp.pattern=strpattern
    'call routine to scan folder and recurse through subfolders
    Call ScanFolder (fl)
  End If
next

'Write results to file
WriteLogFile

'If msgbox("Results are located in docscan.xml" + vbcrlf + "View results now?", 68, "DocScan Report") = 6 then
  'display results in IE
  Set objFile = FSO.GetFile(wscript.scriptfullname)
  'create an XSL file to help in the display of the output
  MakeXSLFile
  Set myIE = CreateObject("InternetExplorer.Application")
  myIE.Navigate FSO.GetParentFolderName(objFile) & "docscan.xml"
  myIE.ToolBar = False
  myIE.StatusBar = False
  myIE.AddressBar = False
  myIE.MenuBar = False
  myIE.Resizable = True
  myIE.TheaterMode = False
  myIE.Width = 650
  myIE.Height = 600
  myIE.Left = 0
  myIE.Top = 0
  myIE.Visible = True
  oShell.AppActivate("Microsoft Internet Explorer")


'**************************************************************************
Function ScanFolder(fl)
  on error resume next
  Dim sfls, sfl, f, fs
  Set fs = fl.files
  if bDebug then wscript.echo oregexp.pattern
  if bDebug then wscript.echo fl.path
  'loop through each file
  For Each f In fs
    if bDebug then wscript.echo f.name
    If f.DateLastModified *{ baseDate and oregexp.test(f.name) then
      intFileCount=intFilecount+1
      intTotalMB = intTotalMB + (f.size/1024)
      DataList.AddNew
      DataList("Path") = f.path
      DataList("Size") = f.size/1024
      DataList("Age") = now-f.DateLastModified
      DataList("LastMod") = f.DateLastModified
      DataList.Update
      err.clear
    End If
  Next
  set sfls = fl.SubFolders
  'recurse through subfolders
  For Each sfl in sfls
    ScanFolder sfl
  Next
End Function

'**************************************************************************
Sub ReadOptions()
Set objFSO = CreateObject("Scripting.FileSystemObject")
if objFSO.fileexists (strFile) then
  Set objTextFile = objFSO.OpenTextFile (strFile, ForReading)
  Do Until objTextFile.AtEndOfStream
    strTextLine = objTextFile.Readline
    select case ucase(mid(strTextLine,1,4))
      case "DIRS"
        strValue=mid(strTextLine,7,len(strTextLine)-7)
        aDirs=split(strValue,";")
      case "EXTS"
        strValue=mid(strTextLine,7,len(strTextLine)-7)
        aExts=split(strValue,";")
      case "AGE="
        dOptionsDate=mid(strTextLine,5)
      case "SORT"
        strSortBy=mid(strTextLine,7,len(strTextLine)-7)
    end select
  Loop
  objTextFile.Close
else
  'no options file - abort
  'kill message box
  retval=oShell.AppActivate("** DocScan Report **")
  if retval then oShell.SendKeys "{Enter}"

  wscript.echo "DocScan Error #1 - no options.ini file found.  Program aborted."
  wscript.quit(1)
end if

if bDebug then
  strmsg="DIRS" & vbcrlf
  for i=lbound(aDirs) to ubound(aDirs)
    strmsg=strmsg & vbtab & aDirs(i) & vbcrlf
  next
  strmsg=strmsg & "EXTS" & vbcrlf
  for i=lbound(aExts) to ubound(aExts)
    strmsg=strmsg & vbtab & aExts(i) & vbcrlf
  next
  strmsg=strmsg & "Date=" & dOptionsDate & vbcrlf
  strmsg=strmsg & "Sort By=" & strSortBy & vbcrlf
  wscript.echo strmsg
end if
End Sub

'**************************************************************************
Sub WriteLogFile()
'open output file to store results
Set log = fso.CreateTextFile("docscan.xml", true)
If Err.Number *{> 0 then
  oShell.Popup "DocScan Error #2 - Cannot Create docscan.xml File: " & Err.Description
  Wscript.Quit(2)
end if

'write header and title info into output file
log.WriteLine "*{?xml version=" & chr(34) & "1.0" & chr(34) & "?>"
log.WriteLine "*{?xml-stylesheet type=" & chr(34) & "text/xsl" & chr(34) & " href=" & chr(34) & "docscan.xsl" & chr(34) & "?>"
log.WriteLine "*{Report>"
log.WriteLine "*{TitleLine1>DocScan Report - Files Older than " & dOptionsDate & " days.*{/TitleLine1>"
log.WriteLine "*{TitleLine2>(As of: " & Date & " @ " & Time & ")*{/TitleLine2>"
log.WriteLine "*{Files>"

DataList.Sort = strSortBy
DataList.MoveFirst
Do Until DataList.EOF
  log.WriteLine "*{File>"
  log.WriteLine "*{FileName>" & DataList.Fields.Item("Path") & "*{/FileName>" & _
      "*{Size>" & formatnumber(DataList.Fields.Item("Size"),1,0,0,-1) & "*{/Size>" & _
      "*{Age>" & formatnumber(DataList.Fields.Item("Age"),0,0,0,-1) & "*{/Age>" & _
      "*{LastMod>" & DataList.Fields.Item("LastMod") & "*{/LastMod>"
  log.WriteLine "*{/File>"
  DataList.MoveNext
Loop


'write trailing data to output file
log.WriteLine "*{/Files>"
log.WriteLine "*{Summary>Total files: " & formatnumber(intFileCount,0,0,0,-1) & " - using " & formatnumber(intTotalMB,1,0,0,-1) & "KB *{/Summary>"
log.WriteLine "*{/Report>"

log.close

End Sub

'**************************************************************************
Sub MakeXSLFile()
  Set xsl = fso.CreateTextFile("docscan.xsl", true)
  xsl.writeline "*{xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0' >"
  xsl.writeline "*{xsl:template match='Report'>"
  xsl.writeline "*{HTML>"
  xsl.writeline "   *{BODY> "
  xsl.writeline "      *{INPUT id='PrintMe' name='PrintMe' onclick='javascript:window.print()' type='button' value='Print'/>"
  xsl.writeline "      *{INPUT id='CloseMe' name='CloseMe' onclick='javascript:window.close()' type='button' value='Close Window'/>"
  xsl.writeline "      *{P style='color: blue; font-size: 16pt; margin-top: 0pt; margin-bottom: 0pt'>*{xsl:value-of select='TitleLine1'/>*{/P>"
  xsl.writeline "      *{P style='color: blue; font-size: 16pt; margin-top: 0pt; margin-bottom: 0pt'>*{xsl:value-of select='TitleLine2'/>*{/P>"
  xsl.writeline "      *{TABLE border='1' style='table-layout: fixed;border: medium none' cellpadding='0' cellspacing='0' width='300'> "
  xsl.writeline "         *{TR bgcolor='yellow'>"
  xsl.writeline "            *{TD width='320' style='font-size: 10pt; padding-right: 5pt; padding-left: 5pt'>File*{/TD>"
  xsl.writeline "            *{TD width='70' align='right' style='font-size: 10pt; padding-right: 5pt; padding-left: 5pt'>Size(KB)*{/TD>"
  xsl.writeline "            *{TD width='50' align='right' style='font-size: 10pt; padding-right: 5pt; padding-left: 5pt'>Age(Days)*{/TD>"
  xsl.writeline "            *{TD width='150' style='font-size: 10pt; padding-right: 5pt; padding-left: 5pt'>Last Modified*{/TD>"
  xsl.writeline "         *{/TR>"
  xsl.writeline "         *{xsl:for-each select='Files/File'>"
  xsl.writeline "            *{TR>   "
  xsl.writeline "               *{TD size='1' style='font-size: 10pt; padding-right: 5pt; padding-left: 5pt'>*{xsl:value-of select='FileName'/>*{/TD>"
  xsl.writeline "               *{TD align='right' style='font-size: 10pt; padding-right: 5pt; padding-left: 5pt'>*{xsl:value-of select='Size'/>*{/TD>"
  xsl.writeline "               *{TD align='right' style='color: red; font-size: 10pt; padding-right: 5pt; padding-left: 5pt'>*{xsl:value-of select='Age'/>*{/TD>"
  xsl.writeline "               *{TD style='font-size: 10pt; padding-right: 5pt; padding-left: 5pt'>*{xsl:value-of select='LastMod'/>*{/TD>"
  xsl.writeline "            *{/TR>"
  xsl.writeline "         *{/xsl:for-each>"
  xsl.writeline "      *{/TABLE>"
  xsl.writeline "      *{P style='color: red; font-size: 16pt'>*{xsl:value-of select='Summary'/>*{/P>"
  xsl.writeline "   *{/BODY>"
  xsl.writeline "*{/HTML>"
  xsl.writeline "*{/xsl:template>"
  xsl.writeline "*{/xsl:stylesheet>"
  xsl.close
End Sub
 

`Contents of OPTIONS.INI
-----------------------
'dirs identifies folder to scan. Scan is done recursively through all sub folders
dirs="c:"

'exts is used to filter only these files for display
exts="doc;xls;ppt;nsf;txt;dat;inf;exe;gif;ini;tmp"

'the age setting limits the files displayed to be this age or older
age=180

'valid sort values are age, path, size or lastmod
sort="lastmod"

 

Start your free trial to view this solution
Question Stats
Zone: Web Development
Question Asked By: justjess59
Solution Provided By: Zvonko
Participating Experts: 2
Solution Grade: A
Views: 454
Translate:
Loading Advertisement...
01.30.2007 at 08:34PM PST, ID: 18433583

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.31.2007 at 01:33AM PST, ID: 18434535

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
01.31.2007 at 01:36AM PST, ID: 18434549

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7 day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Handhelds / PDAs
  • Displays / Monitors
  • Components
  • Networking Hardware
  • Peripherals
  • Laptops/Notebooks
  • Storage
  • Servers
  • Desktops
  • New Users
  • Misc
  • Apple
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMWare
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMWare
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Community Advisor
  • Lounge
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • Community Advisor
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
01.30.2007 at 08:34PM PST, ID: 18433583

Rank: Master

This is a Javascript group, not a VBscript group.
 
01.31.2007 at 01:33AM PST, ID: 18434535

Rank: Genius

All I did was to change two var definitions and change the xml file name:

Const ForReading = 1
Dim aDirs
aDirs="C:\"
Dim aExts
Dim dOptionsDate
dOptionsDate=cdate("01/01/2007")
Dim strSortBy
Dim intFileCount
Dim intTotalMB


And here:
  myIE.Navigate FSO.GetParentFolderName(objFile) & "\docscan.xml"


That was all, and it worked for me.

Accepted Solution
 
01.31.2007 at 01:36AM PST, ID: 18434549

Rank: Genius

Oh, and of course I changed all *{ to < before testing, but that is too obvious.

 
 
20080236-EE-VQP-29