Reputation: 1469
I just started using VBScript today and I'm attempting to get the file size of any file type. My script only returns the file size of the file name provided, but if the file name changes, it renders an error: "file not found"
Here is the script:
CONST bytesToKb = 1024
strFile = "X:\My Docs\Reports\Report1.txt"
SET objFSO = CREATEOBJECT("Scripting.FileSystemObject")
SET objFile = objFSO.GetFile(strFile)
WScript.StdOut.WriteLine CINT(objFile.Size / bytesToKb)
how can I modify the second line to accept any file name, in case the file name Report1.txt is changed to demo.txt? The path to the file will remain the same, just the file name will change. ...Thanks in advance
Upvotes: 1
Views: 9568
Reputation: 18827
You can fix your Main Folder and check all files on it by a loop :
Const bytesToKb = 1024
Set objFSO = CreateObject("Scripting.FileSystemObject")
MainFolder = "E:\TestFolder"
Set objFolder = objFSO.GetFolder(MainFolder)
For each objFile in objFolder.Files
wscript.echo objFile.Name & vbTab & CINT(objFile.Size/bytesToKb) & " kb"
Next
Upvotes: 4