This is the 2nd Tip in a series of Tips on the Microsoft Scripting Runtime Library. The 1st Tip related to Drives, while this Tip will concentrate on the Folders (Directories) in your PC and various methods to retrieve information from and how to manipulate them. The code should be self explanatory and basically documents itself. Should there be any questions related to this Topic, please feel free to ask. -
'Accessing Folder Properties
-
Dim fso As FileSystemObject, fldr As Folder
-
Set fso = New Scripting.FileSystemObject 'OR
-
'Set fso = CreateObject("Scripting.FileSystemObject")
-
-
'Creates an Instance of a Folder
-
Set fldr = fso.GetFolder("C:\Windows\System32")
-
-
Debug.Print "Folder Properties of " & fldr.Path
-
Debug.Print " Folder Name: " & fldr.Name
-
Debug.Print " Folder Size: " & FormatNumber(fldr.Size, 0, vbFalse, vbFalse, vbTrue) & " bytes"
-
Debug.Print " Folder Created: " & fldr.DateCreated
-
Debug.Print " Folder Path: " & fldr.Path
-
Debug.Print " Folder Last Modified: " & fldr.DateLastModified
-
Debug.Print " Folder Last Accessed: " & fldr.DateLastAccessed
-
Debug.Print " Folder Drive: " & fldr.Drive
-
Debug.Print " Files in Folder: " & FormatNumber(fldr.Files.Count, 0, vbFalse, vbFalse, vbTrue) & " files"
-
Debug.Print " Is this a Root Folder: " & fldr.IsRootFolder
-
Debug.Print " Parent Folder: " & fldr.ParentFolder
-
Debug.Print " Folder Path: " & fldr.Path
-
'Could also use the GetBaseName Method of the File System Object
-
Debug.Print " Folder Short Name: " & fldr.ShortName
-
Debug.Print " Folder Short Path: " & fldr.ShortPath
-
Debug.Print " Number of Sub-Folders: " & fldr.SubFolders.Count
-
Debug.Print " Folder Type: " & fldr.Type
-
Debug.Print
-
-
-
'Code that creates a Temporary Folder (fso previously created)
-
Dim msTemporaryFolder As String
-
msTemporaryFolder = fso.GetSpecialFolder(TemporaryFolder).Path & "\"
-
Debug.Print msTemporaryFolder
-
Debug.Print
-
-
-
'Code to see if a Folder exists (fso previously created)
-
'Could also use the FolderExists Method of the File System Object
-
If fso.FolderExists("C:\Test") Then
-
Debug.Print "Folder exists"
-
Else
-
Debug.Print "Folder does not exist"
-
End If
-
Debug.Print
-
-
-
'Code to create a Folder (fso previously created)
-
'Could also use the CreateFolder Method of the File System Object
-
Set fldr = fso.CreateFolder("C:\Windows\System32\Temp Extraction Area")
-
Debug.Print "Created Folder " & fldr.Name
-
-
-
'Code to Delete a Folder (fso previously created)
-
'Could also use the DeleteFolder Method of the File System Object
-
Set fldr = fso.GetFolder("C:\Folder 1\Folder 2\Folder to Delete")
-
fldr.Delete True '"Folder to Delete" is Deleted
-
-
-
'Code to Move a Folder (fso previously created)
-
'Could also use the MoveFolder Method of the File System Object
-
Set fldr = fso.GetFolder("C:\Folder1\Folder2\Folder3")
-
fldr.Move "C:\" '"Folder3" moved to C:\
-
-
-
'Code to Copy a Folder (fso previously created)
-
'Could also use the CopyFolder Method of the File System Object
-
Set fldr = fso.GetFolder("C:\Folder1\Folder2")
-
fldr.Copy "C:\List", True 'Copies "Folder2" to C:\List
OUTPUT: -
Folder Properties of C:\WINDOWS\system32
-
Folder Name: system32
-
Folder Size: 888,994,639 bytes
-
Folder Created: 10/1/2005 2:46:52 AM
-
Folder Path: C:\WINDOWS\system32
-
Folder Last Modified: 2/5/2008 7:04:21 PM
-
Folder Last Accessed: 2/5/2008 7:04:22 PM
-
Folder Drive: C:
-
Files in Folder: 2,309 files
-
Is this a Root Folder: False
-
Parent Folder: C:\WINDOWS
-
Folder Path: C:\WINDOWS\system32
-
Folder Short Name: System32
-
Folder Short Path: C:\Windows\System32
-
Number of Sub-Folders: 50
-
Folder Type: File Folder
-
-
C:\DOCUME~1\Armund\LOCALS~1\Temp\
-
-
Folder exists
-
-
Created Folder Temp Extraction Area
0 5126 Sign in to post your reply or Sign up for a free account.
Similar topics
by: MatthewRoberts |
last post by:
Howdy All,
I am having difficulty with two-way communication across AppDomains in
an attempt to dynamically script applications. Everything works as
expected, except when using ByRef parameters....
|
by: fiona |
last post by:
Catalyst Releases Scripting Editions of SocketTools
Client and server-side development for Active Server Pages and PHP.
Yucca Valley, CA, May 25, 2005 - Catalyst Development Corp...
|
by: Karl Irvin |
last post by:
To use the Textstream object, I had to set a Reference to the Microsoft
Scripting Runtime.
This works good with A2000
Is the Scripting Runtime included with A2002 and A2003 so the Reference...
|
by: Karl Irvin |
last post by:
To use the Textstream object, I had to set a Reference to the Microsoft
Scripting Runtime.
This works good with A2000
Is the Scripting Runtime included with A2002 and A2003 so the Reference...
|
by: frostalicious |
last post by:
Used VB.NET (on my client PC) to convert VB6 executable
to .NET executable. Placed the .exe file on a network drive
on my server. From client, ran .NET Wizards "Trust an
Assembly" to make the...
|
by: PaulieS |
last post by:
Hi all.
Am migrating a customer from IIS5 on W2K server to IIS6 on W2K3.
Zipped all the websites and unzipped them to the identical locations
on new server. Used IISMT to migrate metabase.
...
|
by: ADezii |
last post by:
The next series of Tips will involve the Microsoft Scripting Runtime Library (Scrrun.dll). This Library is, in my humble opinion, one of the most useful and practical Libraries ever created. With the...
|
by: ADezii |
last post by:
This is the 3rd in a series of Tips dealing specifically with the Microsoft Scripting Runtime Library. In this Tip, we'll show you how to return specific Properties relating to Files, as well as...
|
by: ADezii |
last post by:
This is the last in a series of Tips involving the Microsoft Scripting Runtime Library and deals with creating, opening, writing to, reading from, and closing Text Files via this Library. At this...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |