Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get list of folders from local drive using vbscript

Tags:

vbscript

I want to delete all the documents(.doc) files from my computer, for that I know how to get the list of sub folders from a folder, but not how to get the list of folders from the root directory(Ex C:)

subfoldersInFolder = folder.subFolder

Gives all the subfolders of a folder. but supposedly that I want all the folders from C:,

 Set colDrives = objFSO.Drives
 For Each objDrive in colDrives
 objDrive.subFolder  //doesn't work
 Next
like image 700
Cybermonk Avatar asked Jun 27 '14 13:06

Cybermonk


People also ask

How can I get a list of all the subfolders and files present in a directory using PHP?

PHP using scandir() to find folders in a directory The scandir function is an inbuilt function that returns an array of files and directories of a specific directory. It lists the files and directories present inside the path specified by the user.


1 Answers

For Each objFolder In objFSO.GetFolder("C:\").SubFolders
    WScript.Echo objFolder.Path
Next

' or...

For Each objFolder In objFSO.GetDrive("C:").RootFolder.SubFolders
    WScript.Echo objFolder.Path
Next

Edit: sundar nataraj Сундар has asked that I go into more detail.

This is a basic For loop that iterates the SubFolders collection. The SubFolders property is only available for a Folder object. You can get a Folder object for the root in a number of ways. Here are two examples:

  1. Use the GetFolder() function to retrieve a root folder.
  2. Use the RootFolder property of a Drive object.

I've added a WScript.Echo statement in each example to demonstrate the use of the objFolder variable.

like image 69
Bond Avatar answered Oct 04 '22 00:10

Bond