Script to search network shares and delete file

Author Message
Chelmer

  • Total Posts : 1
  • Scores: 0
  • Reward points : 0
  • Joined: 4/27/2005
  • Location:
  • Status: offline
Script to search network shares and delete file Monday, May 16, 2005 3:48 AM (permalink)
0
Hello all

Newbie here, some great posts which I'm sure I will refer to at a later time when needed

Just started learning scripting so apologies for the lack of knowledge - I need some expert assistance if possible

I need to write a script which scans all our network server shares and deletes a specific file if found.

What I have so far is the script reading a text file (which contains all the UNC share paths) and returning each path in StrServerShare. Problem is I'm a bit stuck on how to use each path returned and search all folders for the file - lets say the filename is "test.doc"

Any help will be much appreciated


Const ForReading = 1

Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("h:\servers.txt", ForReading)

i = 0
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop

For Each objItem in objDictionary
StrServerShare = objDictionary.Item(objItem)
Next

 
#1
    token

    • Total Posts : 1917
    • Scores: 0
    • Reward points : 0
    • Joined: 1/14/2005
    • Location:
    • Status: offline
    Re: Script to search network shares and delete file Monday, May 16, 2005 8:10 AM (permalink)
    0
    I see no reasons to put the list of servers into a dictionary, you can start working as soon as the share path is read from the text file from the ".ReadLine" line.

    Below is what you can do. Also, you DO realize that search for these shares WILL take a LONG time to complete if there are significant number of files and directories under the shared folder.

    Option Explicit
    Dim fso, temp, src, ts, file, shell, fileToDelete

    src = "H:\servers.txt"
    fileToDelete = "test.doc"

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set shell = CreateObject("WScript.Shell")
    Set ts = fso.OpenTextFile(src,1)

    Do Until ts.AtEndOfStream
    temp = ts.ReadLine
    Set file = shell.Exec("cmd /c dir /a/s/b " & temp)
    Do Until file.StdOut.AtEndOfStream
    temp = file.StdOut.ReadLine
    If fso.GetBaseName(temp) = fileToDelete Then
    fso.DeleteFile temp
    End If
    Loop
    Loop


     
    #2

      Online Bookmarks Sharing: Share/Bookmark

      Jump to:

      Current active users

      There are 0 members and 1 guests.

      Icon Legend and Permission

      • New Messages
      • No New Messages
      • Hot Topic w/ New Messages
      • Hot Topic w/o New Messages
      • Locked w/ New Messages
      • Locked w/o New Messages
      • Read Message
      • Post New Thread
      • Reply to message
      • Post New Poll
      • Submit Vote
      • Post reward post
      • Delete my own posts
      • Delete my own threads
      • Rate post

      2000-2012 ASPPlayground.NET Forum Version 3.9