locked
Locate files using a vb script RRS feed

  • Question

  • Hi everybody,

    I am a network guy with 0 programmings skills :) I'm getting better with scripting slowly but surely...

    I have a customer that needs to find where are located Groupewise archives for around 80 users. We will then move them to a specific location on the network. The customer will do this manually since they have configuration change to do on each mailbox.

    The archive name are always in this format OF???ARC .

    My script work but only for explicit file name. I would need to use a regex or something so my search result find the files.

    I need to search on c:\*.* because they could be possibly everywhere.

    I dont need to do any action on the files just find them and write result to file. Like I said I have no programming skills and I found all the piece looking on forums.

    Thanks for your help, it is probably a small thing but I cant manage to find it.

    Regards,

    Mathieu

    See my script is below

    I did REM my objregex since its not working anyway.

    Dim WshShell
    Set WshShell = CreateObject("WScript.Shell")
    Set WshNetwork = CreateObject("WScript.Network")
    strComputer = WshNetwork.ComputerName

    RemSet objRegEx = CreateObject("VBScript.RegExp")
    RemobjRegEx.Pattern = "OF...ARC"

    Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

    Set colFiles = objWMIService.ExecQuery _
        ("Select * from CIM_DataFile Where Filename = 'OFxyxARC' ") 

    If colFiles.Count = 0Then
       WScript.echo ("no file found")
    Rem  Wscript.quit
    EndIf


        Set objFSO = CreateObject("Scripting.FileSystemObject")
        Set objTextFile = objFSO.CreateTextFile("c:\scripts\" & strComputer & ".txt")

    ForEach objFilein colFiles
        objTextFile.Write(objFile.Drive & objFile.Path & ",")
        objTextFile.Write(objFile.FileName & "." & objFile.Extension & ",")
        objTextFile.Write(objFile.FileSize & vbCrLf)
    Next

    objTextFile.Close

    By the way. I can't use powershell. Only Windows XP with a lot of missing patches and Windows 2003 servers available in the forest/domain


    Tuesday, January 7, 2014 5:27 PM

Answers

  • You will get errors because many folders are protected.  You can safely ignore all errors.  The errors will not appear in the file.

    For those file names this will work:

    dir OF*ARC* /s >list.txt 2>errors.txt

    This will hide all of the errors.


    ¯\_(ツ)_/¯

    • Marked as answer by Bill_Stewart Tuesday, February 18, 2014 3:03 AM
    Tuesday, January 7, 2014 7:08 PM

All replies

  • Bath is easiest

    dir OF???ARC* /s >listing.txt

    That will search everywhere on the c drive.

     


    ¯\_(ツ)_/¯

    Tuesday, January 7, 2014 5:39 PM
  • To search with WMI use the % character as a place holder:

    Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile Where Filename LIKE 'OF___ARC%' ") 


    ¯\_(ツ)_/¯



    • Edited by jrv Tuesday, January 7, 2014 5:43 PM
    Tuesday, January 7, 2014 5:40 PM
  • I actually tried with dir at first but using dir do not work using a script. I tested it at home and I have no issue but here... nothing will do... I have a file not found error or something similar.(translated from french).

    Unless you know why it does this ?

    So I don't need a REGex to search the files ? Just to make sure I was clear. Here are some example of file name I Could find.

    OF123ARC

    OF452ARC

    OFABAARC

    Thanks for the quick answers.

    Tuesday, January 7, 2014 6:57 PM
  • I actually tried with dir at first but using dir do not work using a script.

    I have used the cmd.exe 'dir' command a number of times in different scripts. What gives you the impression that it doesn't work?

    Bill

    Tuesday, January 7, 2014 7:05 PM
  • You will get errors because many folders are protected.  You can safely ignore all errors.  The errors will not appear in the file.

    For those file names this will work:

    dir OF*ARC* /s >list.txt 2>errors.txt

    This will hide all of the errors.


    ¯\_(ツ)_/¯

    • Marked as answer by Bill_Stewart Tuesday, February 18, 2014 3:03 AM
    Tuesday, January 7, 2014 7:08 PM
  • Well I dont know what's up but now it is working with dir using a filesearch.cmd

    When I was running the cmd I had an issue but I think it was a typo in the path where the file should be located....

    I will keep my vbs as well. I will try again with the dir command and call the .cmd in their login script and see what's up !

    Thanks scripting guys!

    Tuesday, January 7, 2014 8:19 PM