The FileSystemObject VBA DeleteFile function deletes a specified file or files. The functions allows you to use wildcards (*) to delete multiple files matching a specific file path pattern which saves a lot of time for easy deletion scenarios.
- 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 DeleteFile Syntax
1 | fso.DeleteFile( filename, [ force ] ) |
- filename – The location names of file(s) to delete. You can use wildcards such as *.* to specify more than a single file matching the pattern.
- force – Optional. If True only read-only files are deleted. If False any files are deleted. False is default.
Examples
1 2 3 4 5 6 7 8 9 10 11 12 13 | Set fso = CreateObject( "Scripting.FileSystemObject" ) 'Delete file Hello.xlsx fso.DeleteFile "c:\Src\Hello.xlsx" 'Delete all files with XLSX extension in C:\Src folder fso.DeleteFile "c:\Src\*.xlsx" 'Delete all files in specified folder fso.DeleteFile "c:\Src\*.*" 'Delete all files in subfolders of C:\Src fso.DeleteFile "C:\Src\*\*.*" |