View Full Version : add a file counter (W2K)
I have a VBscript that copies files when the user logs on, I need to display to the user how many files were copied and the size of the files.
Mosaic1
04-02-2003, 10:33 AM
Is the script very large? If not, you might post it here. There would be several ways to do this. You might create a text file and add the name of each file copied and its size, then open the text file. Or use a message box to display the information.
The code is a bit long. I will try using a message box. Thanks!
I still have not worked out the message box. In the meantime, I am also trying to research how to read in information from a settings.cfg file (into my vbscript). Example: user will modify settings.cfg file with the following information: file to move and where to move it. I need to then use this information in the current script. If you can help, I can post the code.
You could use something like this;
SourceFolder = "C:\Copied\test"
TargetFolder = "C:\Copied\test2"
' Do the usual stuff
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFolder = fso.GetFolder(SourceFolder)
For Each Dfile In myFolder.Files
' Get a handle to the file
Set MyFile = fso.GetFile(Dfile.path)
' Copy the file to the TargetFolder
'MyFile.Copy TargetFolder & "\" & Dfile.Name, True
' Increment the file counter by 1
FileCount = FileCount + 1
' Add its size to the total size of copied files
FileSz = FileSz + MyFile.Size
' Do it all again for the next file in the folder
Next
Wscript.Echo "Copied " & FileCount & " Files. With a total " &_
"size of: " & Round(FileSz / 1048576, 1) & "MB"
Set fso = Nothing
Set myFolder = Nothing
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@
'@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@
Or you could use Internet Explorer as a File Copy dialog.
This script will display a progress bar, the full name of the file being copied and the total size of the files that have been copied so far.
Note: If unmodified, this script requires internet connection to function properly.
SourceFolder = "C:\Copied\test"
TargetFolder = "C:\Copied\test2"
Set WSHShell = WScript.CreateObject("WScript.Shell")
Set IE = WScript.CreateObject("InternetExplorer.Application")
with ie
.width = 600
.height = 200
.top = 0
.left = 0
.menubar = 0
.statusbar = 0
.resizable = 0
.toolbar = 0
.visible = 1
.AddressBar = 0
CreateHTML_File
.navigate ("c:\Progress.html")
.document.title = "File copy progress"
End with
Do While (IE.Busy)
WScript.Sleep 500
Loop
Set fso = CreateObject("Scripting.FileSystemObject")
Set myFolder = fso.GetFolder(SourceFolder)
FolderSize = Round(myFolder.Size / 1048576,1)
If myFolder.Files.Count > 0 Then
Percent = 100 / myFolder.Files.Count
For Each Dfile In myFolder.Files
Set MyFile = fso.GetFile(Dfile.path)
'Commented for testing. No files will be copied.
'MyFile.Copy TargetFolder & "\" & Dfile.Name, True
FileCount = FileCount + 1
FileSz = FileSz + MyFile.Size
ie.document.All.text1.value = Dfile.path
ie.document.script.incrCount(Percent)
ie.document.All.text2.value = Round(FileSz / 1048576, 1) & "/" & FolderSize & "MB"
WshShell.AppActivate "File copy progress"
Next
End If
For i = 10 To 0 Step -1
ie.document.body.innerHTML = "Copyed " & FileCount & " Files <BR>"&_
"Total Size: " & Round(FileSz / 1048576, 1) & "MB <BR><BR>"&_
"<center><B> Exiting in " & i & " seconds"
wscript.sleep 1000
Next
ie.quit
Set DelFile = FSO.GetFile("c:\Progress.html")
DelFile.Delete
Sub CreateHTML_File()
ProgressDialog = "c:\Progress.html"
Set FSo = CreateObject("Scripting.FileSystemObject")
Set TempFile = FSo.CreateTextFile(ProgressDialog, True)
HTML_Code = "<head><title>File copy progress</title></head><center>Copying...<BR>" &_
"<DIV ALIGN=CENTER><input type='text' name='text1' value='' SIZE='85' border='0'><BR>" &_
"<input type='text' name='text2' value='' SIZE='20' border='0'><BR><BR>" &_
"<script language='javascript' src='http://www.dynamicdrive.com/dynamicindex11/percent_bar.js'>" &_
"</script></DIV></center></html>"
TempFile.writeline HTML_Code
TempFile.close
End Sub
Set fso = Nothing
Set myFolder = Nothing
Set Dfile = Nothing
Jama
Powered by vBulletin™ Version 4.1.0 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.