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

List of files being moved vbscript

Discussion in 'Programming' started by DocDriza, Oct 31, 2009.

  1. DocDriza

    DocDriza New Member

    Joined:
    Oct 31, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hello,

    I am new to the scripting world, and want to learn. I i have a VBScript that i have that will copy files from one drive to another user specified drive. I would like to see a list of files being moved over in real time. For just in case im not being clear enough, look at this code i have for a batch file:

    @echo off

    echo ***********************************
    echo * Copying files to your hard drive *
    echo * *
    echo ***********************************

    :: copies the files from the EUSB to the hard drive
    xcopy "*" "C:\My USB Backup\" /Y /E /R

    ECHO.
    echo Backup Complete!

    When this batch script runs, you get an output similar to the following:

    F:Cover Letter.pdf
    F:Resume.pdf
    F:Review 2009.PDF
    F:backup_usb.vbs
    F:Copy to drive.vbs
    F:backup_usb.bat
    6 File(s) copied

    is there any way to translate this into vbs?
     
  2. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    Why do you want to move it into VBS if it's happening with Batch File?
    Also what do you mean by, "to see a list of files being moved over in real time"?
     
  3. SaswatPadhi

    SaswatPadhi ~ Б0ЯИ Τ0 С0δЭ ~

    Joined:
    May 5, 2009
    Messages:
    1,343
    Likes Received:
    55
    Trophy Points:
    0
    Occupation:
    STUDENT !
    Location:
    Orissa, INDIA
    Home Page:
    Hmm ... real-time notifications ...

    Well, one method you can use is, you can use WScript.Shell's Popup method to display timed-message-boxes, like :
    Code:
    For Each TFile In MySource
        FileSys.CopyFile TFile.Path, MyDest.Path
        Count += 1
        objShell.Popup TFile.Path+" successfully copied !", 1, Str(Count)+" Files copied", 64
    Next
    
    But, the least count achievable that way would be 1 sec. :(
    With super-fast transfer rates, many of the files would be copied in fraction of second.
    So, the above method won't be much useful.


    After searching for a long time, I found something really cooool :D
    (here : http://www.robvanderwoude.com/vbstech_ui_progress.php)

    You can simply replace the Popup in the above code with ProgressMsg.

    For example :
    Code:
    ' Makes the object a Public object (Critical!)
    Dim objProgressMsg
    
    ' *** Usage example
    sMySource="C:\TestSource\"
    sMyDest="C:\TestDest\"
    
    Dim FSO
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Dim MySource, MySourceFile
    Set MySource = FSO.GetFolder(sMySource)
    
    For Each MySourceFile In MySource.Files
    	FSO.CopyFile MySourceFile.Path, sMyDest
            ProgressMsg "", ""
            ProgressMsg MySourceFile.Path, "Testing .."
    Next
    
    ProgressMsg "", ""
    MsgBox "Copy Done !!"
    WScript.Quit
    ' *** End Usage example
    
    Function ProgressMsg( strMessage, strWindowTitle )
    ' Written by Denis St-Pierre
    ' Displays a progress message box that the originating script can kill in both 2k and XP
    ' If StrMessage is blank, take down previous progress message box
    ' Using 4096 in Msgbox below makes the progress message float on top of things
    ' CAVEAT: You must have   Dim ObjProgressMsg   at the top of your script for this to work as described
        Set wshShell = WScript.CreateObject( "WScript.Shell" )
        strTEMP = wshShell.ExpandEnvironmentStrings( "%TEMP%" )
        If strMessage = "" Then
            ' Disable Error Checking in case objProgressMsg doesn't exists yet
            On Error Resume Next
            ' Kill ProgressMsg
            objProgressMsg.Terminate( )
            ' Re-enable Error Checking
            On Error Goto 0
            Exit Function
        End If
        Set objFSO = CreateObject("Scripting.FileSystemObject")
        strTempVBS = strTEMP + "\" & "Message.vbs"     'Control File for reboot
    
        ' Create Message.vbs, True=overwrite
        Set objTempMessage = objFSO.CreateTextFile( strTempVBS, True )
        objTempMessage.WriteLine( "MsgBox""" & strMessage & """, 4096, """ & strWindowTitle & """" )
        objTempMessage.Close
    
        ' Disable Error Checking in case objProgressMsg doesn't exists yet
        On Error Resume Next
        ' Kills the Previous ProgressMsg
        objProgressMsg.Terminate( )
        ' Re-enable Error Checking
        On Error Goto 0
    
        ' Trigger objProgressMsg and keep an object on it
        Set objProgressMsg = WshShell.Exec( "%windir%\system32\wscript.exe " & strTempVBS )
    
        Set wshShell = Nothing
        Set objFSO   = Nothing
    End Function
    
    Works gr8 :)
    I hope this will help ..
     

Share This Page