0

hey guys, I really need help with this VBScript problem:

Ask the user to enter the folder name and filename. Test whether the file exists in the given folder. If the file exists, display the file size in MBs up to 2 decimal digits. If the file does not exist, display an error message as "File does not exist"

any help would be really appreciated!

Thanks

2
Contributors
1
Reply
3
Views
5 Years
Discussion Span
Last Post by Jx_Man
0

Try this :

FolderName =Inputbox("Enter Folder Name","Folder Name")
FileName =Inputbox("Enter File Name","File Name")

Const bytesToMb = 1048576

Set objFSO = CreateObject("Scripting.FileSystemObject")

ShowSubFolders objFSO.GetFolder(FolderName)

Sub ShowSubFolders(Folder)

    temp = 0 
    For Each file In Folder.Files
        Set objCurFile = objFSO.GetFile(file)
        If UCase(objCurFile.Name) = UCase(FileName) Then  
            temp = temp + 1
            strFile = Folder & "\" & FileName
        End If
    Next

    Set objFile = objFSO.GetFile(strFile)

    If temp > 0 Then
        wscript.echo "File Size: " & Round(objFile.Size / bytesToMb, 2) & " Mb"
    Else
        WScript.Echo "File does not exist"
    End if

End Sub

Edited by Jx_Man

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.