1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Multi-Step Script (possible)

Discussion in 'Visual Basic ( VB )' started by ScriptNoob, Nov 20, 2014.

  1. ScriptNoob

    ScriptNoob New Member

    Joined:
    Nov 20, 2014
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Occupation:
    Sr Infrastructure Architect
    Location:
    Texas
    Hi all new to the site and as the name implies, I am a script noob. Most my experience has been via Google and modifying scripts for my needs.

    I'm usually pretty good about finding what I need but I have this script and I cannot for the life of me, find how to make it work.

    What I am trying to do:

    1.) first search a folder (c:\test) and list all files with in that folder. It also needs to do subfolders c:\test\folder1 and list its files and output this to a text file. (output1.txt)


    2.) At the same time of the search look for any file names with special characters ($, #, @ in the name so #myfile.xdoc or @document1.xls) If any files with special characters are found, rename them by removing the special character and output to a separate text file. (specialfiles.txt)


    4.) Lastly, re-scan again and output to file (finalout.txt)

    So for I have this:
    On Error Resume Next

    Const WINDOW_HANDLE = 0
    Const BIF_EDITBOX = &H10
    Const BIF_NONEWFOLDER = &H0200
    Const BIF_RETURNONLYFSDIRS = &H1

    Set objShell = CreateObject("Shell.Application")
    Set wshShell = CreateObject("WScript.Shell")
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    '**Browse For Folder To Be Processed
    strPrompt = "Please select the folder to process."
    intOptions = BIF_RETURNONLYFSDIRS + BIF_NONEWFOLDER + BIF_EDITBOX
    strFolderPath = "C:\TestFolder\"

    Set objNewFile = objFSO.CreateTextFile(strFolderPath & "\preODfilelist.txt", True)
    Set objFolder = objFSO.GetFolder(strFolderPath)
    Set objColFiles = objFolder.Files

    ' CHANGE STARTS HERE :
    Set objColFolders = objFolder.SubFolders

    For Each tfolder In objColFolders
    objNewFile.WriteLine(tfolder.Name)
    Next
    ' CHANGE DONE.

    For Each file In objColFiles
    objNewFile.WriteLine(file.Name)
    Next
    objNewFile.Close

    '**Browse4Folder Function
    Function Browse4Folder(strPrompt, intOptions, strRoot)
    Dim objFolder, objFolderItem

    On Error Resume Next

    Set objFolder = objShell.BrowseForFolder(0, strPrompt, intOptions, strRoot)
    If (objFolder Is Nothing) Then
    Wscript.Quit
    End If
    Set objFolderItem = objFolder.Self
    Browse4Folder = objFolderItem.Path
    Set objFolderItem = Nothing
    Set objFolder = Nothing
    End Function


    and my output is the following: *note the sub folders are not listing any of its files*

    New folder
    New folder (2)
    New folder (3)
    New folder (4)
    #New Text Document (5).txt
    @New Microsoft Word Document.docx
    DellStorage_SC4020_Spec_Sheet_030714.pdf
    Dell_Compellent_Flash_Optimized_Data_Progression_Whitepaper.pdf
    FluidFS_in_a_Multi-protocol_Environment_101613.pdf
    New Microsoft Excel Worksheet (2).xlsx
    New Microsoft Excel Worksheet.xlsx
    New Microsoft Word Document (2).docx
    New Text Document (2).txt
    New Text Document (3).txt
    New Text Document (4).txt
    New Text Document.txt
    preODfilelist.txt

    This is where I am stuck.

    this article (G4E/articles/list-files-folder-using-vbscript-t927/page3) was extremely helpfully for step 1 but I'm stuck now

    Any help would be greatly appreciated

    Hopefully I provided enough information
     

Share This Page