Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

convert vba to vb script

Posted on 2013-01-03
2
Medium Priority
?
367 Views
Last Modified: 2013-01-17
I have the following VBA code that works fine. How do I convert it to run in VB script? I understand Dir is not supported in VB script. Is there a substitute?  

Basically, I am looking for Microsoft Word documents in all subfolders on all connected network drives that have  the phrases "Progress Report" or "Consultation Report" in their name.  If there are two files with matching names except one file has "Signed" appended to it, delete the file without "Signed".  Also delete any files that start with "~$".

TIA
Sub ClearAllUneededFiles()
Dim fs

Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("\\Jane-pc\jane's files\Patent Records\FindUnsignedDocuments.doc") Then
    ClearUneededFiles "\\Jane-pc\jane's files\Patent Records\"
    ClearUneededFiles "\\Jane-pc\jane's files\Patent Records\_NOT SEEN\"
End If
If fs.FileExists("\\FUJITU\My Documents\JANE'S FILES\Patent Records\FindUnsignedDocuments.doc") Then
    ClearUneededFiles "\\FUJITU\My Documents\JANE'S FILES\Patent Records\"
    ClearUneededFiles "\\FUJITU\My Documents\JANE'S FILES\Patent Records\_NOT SEEN\"
End If
If fs.FileExists("\\DESKTOP\My Documents\Jane's files\Patent Records\FindUnsignedDocuments.doc") Then
    ClearUneededFiles "\\DESKTOP\My Documents\Jane's files\Patent Records\"
    ClearUneededFiles "\\DESKTOP\My Documents\Jane's files\Patent Records\_NOT SEEN\"
End If
ActiveDocument.SaveAs Environ("temp") & "\temp.doc"
Application.Quit wdPromptToSaveChanges
End Sub


Sub ClearUneededFiles(mypath)
Dim DirList()
Dim counter
Dim MyName
Dim fs

Set fs = CreateObject("Scripting.FileSystemObject")

counter = 0
ReDim DirList(1)

On Error Resume Next
MyName = Dir(mypath, vbDirectory)
If Err = 53 Then
    Exit Sub
End If
On Error GoTo 0

Do While MyName <> ""   ' Start the loop to find subfolders
    If (GetAttr(mypath & MyName) And vbDirectory) = vbDirectory Then
        If MyName <> "." And MyName <> ".." And InStr(1, MyName, "_") = 0 Then
            ReDim Preserve DirList(counter)
            DirList(counter) = mypath & MyName
            counter = counter + 1
        End If
    End If
    MyName = Dir    ' Get next entry.
Loop
For counter = 0 To UBound(DirList)
    MyName = Dir(DirList(counter) & "\*.doc")

    Do While MyName <> ""   ' Start the loop to find files in each subfolder
        If InStr(1, MyName, "Consultation Report") > 0 Or InStr(1, MyName, "Progress Report") > 0 Then
            If InStr(1, MyName, "Signed") = 0 Then
                If fs.FileExists(DirList(counter) & "\" & Left(MyName, Len(MyName) - 4) & " Signed.doc") Then
                    Kill DirList(counter) & "\" & MyName
                ElseIf Left(MyName, 2) = "~$" Then
                    Kill DirList(counter) & "\" & MyName
                End If
            End If
        End If
    MyName = Dir    ' Get next entry.
    Loop
Next
End Sub

Open in new window

0
Comment
Question by:thenelson
2 Comments
 
LVL 12

Accepted Solution

by:
HugoHiasl earned 2000 total points
ID: 38739413
You are already using a FileSystemObject.

You could use the methods of this object:

msdn.microsoft.com/en-us/library/aa262402(v=vs.60).aspx
0
 
LVL 39

Author Closing Comment

by:thenelson
ID: 38789525
thanks!
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying 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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

885 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