Create a VBScript script (w3_firstname_lastname.vbs) that takes one parameter (folder name) to do the following

1) List all files names, size, date created in the given folder
2) Parameter = Root Folder name The script should check and validate the folder name
3) Optionally, you can save the list into a file "Results.txt" using the redirection operator or by creating the file in the script.
4) Make sure to include comment block (flowerbox) in your code.
5) Sample run:- C:\entd261>cscript.exe w3_sammy_abaza.vbs "c:\entd261" >results.txt

Respuesta :

Answer:

VBScript is given below

Explanation:

As per the given details the program should be as follows:

if (WScript.Arguments.Count = 0) then

WScript.Echo "Missing parameters"

else

'Declare the File System object to be used

Dim fso

'Declare the path variable to be used for storing the path entered by user

Dim path

'Create the File System object using the FileSystemObject class

Set fso = CreateObject("Scripting.FileSystemObject")

'initialize the path

path = WScript.Arguments(0)

'Check if the path exists

exists = fso.FolderExists(path)

if (exists) then

'declare a constant of size 1024 since 1024 bytes = 1 Kb

CONST bytesToKb = 1024

'Print the selected path

WScript.Echo "Selected Path " & WScript.Arguments(0)

'get the folder on path

Set inDir=fso.GetFolder(path)

'Create the file to store the output results

Set outFile = fso.CreateTextFile("Results.txt",True)

'Print the name, date created and size of each file and store the same in output file

For Each objFile in inDir.Files

  'Calculate the padding needed for File Name. Assuming the maximum length of file name is 40 characters

  namePadding = 40 - Len(objFile.Name)

  'Calculate the padding needed for Date

  datePadding = 30 - Len(objFile.DateCreated)

  'Add spaces to file Name so that same can be printed in a tabular format

  fileName = objFile.Name & Space(namePadding)

  'Add spaces to date so that same can be printed in a tabular format

  dateCreated = objFile.DateCreated & Space(datePadding)

  'Print the details on screen

  Wscript.Echo fileName & dateCreated & CINT(objFile.Size / bytesToKb) & "Kb"

  'Store the details in ouput file with a newline character at the end

  outFile.Write fileName & dateCreated & CINT(objFile.Size / bytesToKb) & "Kb" & vbCrLf

Next

'Close the output file once the loop ends

outFile.Close

else

'Print a message if the path does not exist

WScript.Echo "Invalid Path Entered"

end if

end if

In this exercise we have to use the programming knowledge to program from python in this way, so:

The code to solve this programming can be found in the image attached below.

As per the given details the program should be as follows:

if (WScript.Arguments.Count = 0) then

WScript.Echo "Missing parameters"

else

'Declare the File System object to be used

Dim fso

'Declare the path variable to be used for storing the path entered by user

Dim path

'Create the File System object using the FileSystemObject class

Set fso = CreateObject("Scripting.FileSystemObject")

'initialize the path

path = WScript.Arguments(0)

'Check if the path exists

exists = fso.FolderExists(path)

if (exists) then

'declare a constant of size 1024 since 1024 bytes = 1 Kb

CONST bytesToKb = 1024

'Print the selected path

WScript.Echo "Selected Path " & WScript.Arguments(0)

'get the folder on path

Set inDir=fso.GetFolder(path)

'Create the file to store the output results

Set outFile = fso.CreateTextFile("Results.txt",True)

For Each objFile in inDir.Files

 namePadding = 40 - Len(objFile.Name)

 'Calculate the padding needed for Date

 datePadding = 30 - Len(objFile.DateCreated)

   fileName = objFile.Name & Space(namePadding)

  dateCreated = objFile.DateCreated & Space(datePadding)

 'Print the details on screen

 Wscript.Echo fileName & dateCreated & CINT(objFile.Size / bytesToKb) & "Kb"

 'Store the details in ouput file with a newline character at the end

 outFile.Write fileName & dateCreated & CINT(objFile.Size / bytesToKb) & "Kb" & vbCrLf

Next

'Close the output file once the loop ends

outFile.Close

else

'Print a message if the path does not exist

WScript.Echo "Invalid Path Entered"

end if

end if

See more about python at brainly.com/question/26104476

Ver imagen lhmarianateixeira