Solved

need help with vbscript

Posted on 2016-09-08
4
27 Views
Last Modified: 2016-09-28
hi ,
I am just beginner to vbscript, I am trying to find files in my windows server based on last modified date and particular extension, please help me with this
0
Comment
Question by:hema latha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 18

Accepted Solution

by:
xtermie earned 250 total points (awarded by participants)
ID: 41791193
For the particular extension try:

Set objfso = CreateObject("Scripting.FileSystemObject")
objStartFolder = "C:\Test"                                                                'Set your path here
Set objFolder = objfso.GetFolder(objStartFolder)

For Each objFile In objFolder.Files
          If objfso.GetExtensionName(objFile) = "jpeg" Then          'specify your extension here
                                       Wscript.Echo objFile.Name
          End If
Next

Open in new window


and if you would like an output for that, try:
Option Explicit 'force all variables to be declared

Const ForWriting = 2
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim objTS 'Text Stream Object
Set objTS = objFSO.OpenTextFile("C:\test\Output.txt", ForWriting, True)
Recurse objFSO.GetFolder("C:\test\")                        'set your folder here
objTS.Close()

Sub Recurse(objFolder)
    Dim objFile, objSubFolder

    For Each objFile In objFolder.Files
        If LCase(objFSO.GetExtensionName(objFile.Name)) = "jpeg" Then                  'set your extension here
            objTS.WriteLine(objfile.Path)
        End If
    Next

    For Each objSubFolder In objFolder.SubFolders
        Recurse objSubFolder
    Next
End Sub

Open in new window

0
 
LVL 18

Assisted Solution

by:xtermie
xtermie earned 250 total points (awarded by participants)
ID: 41791202
For the modified data read this other EE question (w answer)
https://www.experts-exchange.com/questions/23899745/VBScript-to-read-file-modified-date.html
0
 
LVL 54

Assisted Solution

by:Bill Prew
Bill Prew earned 250 total points (awarded by participants)
ID: 41791429
This should be a decent starting point, see what you can do with this.  Specify the relevant info in the CONST lines at the top.  This will search recursively in all folders under the base folder.  And looks for files modified more than the number of days specified.

' Specify base folder to list files under, age in days of files, and extension to select
Const strDir = "C:\Temp"
Const intAge = 30
Const strExt = "txt"

' Create file system object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

' Remove old files recursively
ListFiles objFSO.GetFolder(strDir)

Sub ListFiles(objFolder)
    On Error Resume Next

    ' List any files older than specified days from this folder
    For Each objFile In objFolder.Files
        If LCase(objFSO.GetExtensionName(objFile.Path)) = LCase(strExt) Then
            intFileAge = DateDiff("d", objFile.DateLastModified, Now)
            If intFileAge > intAge Then
                Wscript.Echo "File: """ & objFile.Path & """ Age: " & intFileAge & """."
            End If
        End If
    Next

    ' See if we were able to access this folder, if not don't recurse into it
    If Err.Number = 0 Then
        ' Remove all older files in any subfolders of this one
        For Each objSubFolder In objFolder.Subfolders
            ListFiles objSubFolder
        Next

    End If
End Sub

Open in new window

~bp
0
 
LVL 18

Expert Comment

by:xtermie
ID: 41819433
Valid commends and recommedations
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question