Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Programming (http://www.go4expert.com/forums/programming-forum/)
-   -   List of files being moved vbscript (http://www.go4expert.com/forums/list-files-moved-vbscript-t19936/)

DocDriza 1Nov2009 00:27

List of files being moved vbscript
 
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?

nimesh 1Nov2009 15:44

Re: List of files being moved vbscript
 
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"?

SaswatPadhi 1Nov2009 18:15

Re: List of files being moved vbscript
 
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: VB

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: VB

' 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 ..


All times are GMT +5.5. The time now is 14:29.