The FileSystemObject VBA GetFolder function will return a Folder object on which you can run several methods (Copy, Delete, Move, AddFolders) and obtain folder properties (e.g. Date Created, Size, Type etc. see more below).
VBA FileSystemObject Methods
- BuildPath
- CopyFile
- CopyFolder
- CreateFolder
- CreateTextFile
- DeleteFile
- DeleteFolder
- DriveExists
- FileExists
- FolderExists
- GetAbsolutePathName
- GetBaseName
- GetDrive
- GetDriveName
- GetExtensionName
- GetFile
- GetFileName
- GetFolder
- GetParentFolderName
- GetSpecialFolder
- GetTempName
- MoveFile
- MoveFolder
- OpenTextFile
VBA GetFolder Syntax
fso.GetFolder( path )
path
The path to the folder for which a Folder object is to be returned.
VBA GetFolder Examples
Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFolder("C:\Src\") 'Return the Folder object 'Now we can obtain various properties of the Folder Debug.Print f.DateCreated 'Date when folder was created Debug.Print f.Drive 'Result: "C:" - the drive of the folder path Debug.Print f.Name 'Result: "Src" - name of the folder Debug.Print f.ParentFolder 'Result: "C:\" - name of the parent folder Debug.Print f.Path 'Result: "C:\Src" - path to the folder Debug.Print f.ShortPath 'Returns short path to file with 8.3 naming convention Debug.Print f.Size 'Size of folder in bytes Debug.Print f.Type 'Result: "SystemFolder" - type which is folder by default 'We can also run several basic folder operations on the folder f.Copy "C:\NewFolder\" 'Copy folder f.Move "C:\NewFolder\" 'Move the file to new destination f.Delete 'Delete the folder f.AddFolder "NewSubFolder" 'Add a subfolder by name to the Folder 'The Folder contains also a collection of Folders and Files For each fc in f.Folders 'Print all folders in Folder Debug.Print fc.Name Next fc For each fc in f.Files 'Print all files in Folder Debug.Print fc.Name Next fc