Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
deleting file(s) by their file extension
Does anyone knows how to write a simple code to delete a file or file by their file extension? Thanks in advance. Joh -- jt4 ----------------------------------------------------------------------- jt46's Profile: http://www.excelforum.com/member.php...fo&userid=1515 View this thread: http://www.excelforum.com/showthread.php?threadid=26891 |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
deleting file(s) by their file extension
Kill "C:\test1\*.txt"
These don't go to the recycle bin, so make sure you know what you want to delete. -- Regards, Tom Ogilvy "jt46" wrote in message ... Does anyone knows how to write a simple code to delete a file or files by their file extension? Thanks in advance. John -- jt46 ------------------------------------------------------------------------ jt46's Profile: http://www.excelforum.com/member.php...o&userid=15154 View this thread: http://www.excelforum.com/showthread...hreadid=268917 |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
deleting file(s) by their file extension
This function will delete all files with a given extension in a specified
folder; e.g. Clean("C:\TEMP","xml") will delete any .xml files in the C:\TEMP folder. It returns the number of files deleted and also (if you need to check the file names) prints the files deleted in the debugger. Public Function Clean(FolderPath As String, Extension As String) As Integer Dim FileName As String, CountFiles As Integer CountFiles = 0 FileName = Dir(FolderPath & "\*." & Extension) While FileName < "" debug.print FolderPath & "\" & FileName Kill FolderPath & "\" & FileName CountFiles = CountFiles + 1 FileName = Dir Wend Clean = CountFiles End Function "jt46" wrote: Does anyone knows how to write a simple code to delete a file or files by their file extension? Thanks in advance. John -- jt46 ------------------------------------------------------------------------ jt46's Profile: http://www.excelforum.com/member.php...o&userid=15154 View this thread: http://www.excelforum.com/showthread...hreadid=268917 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
deleting file(s) by their file extension
Altering files in a Dir Loop can cause problems - or so sayeth the Knowledge
Base. I have never encountered any, but one never knows. In any event, this can all be done in one line, so no use looping or using Dir. Public Function Clean(FolderPath As String, Extension As String) Kill FolderPath & "*." & Extension End Sub Error checking for valid arguments can be added. -- Regards, Tom Ogilvy "K Dales" wrote in message ... This function will delete all files with a given extension in a specified folder; e.g. Clean("C:\TEMP","xml") will delete any .xml files in the C:\TEMP folder. It returns the number of files deleted and also (if you need to check the file names) prints the files deleted in the debugger. Public Function Clean(FolderPath As String, Extension As String) As Integer Dim FileName As String, CountFiles As Integer CountFiles = 0 FileName = Dir(FolderPath & "\*." & Extension) While FileName < "" debug.print FolderPath & "\" & FileName Kill FolderPath & "\" & FileName CountFiles = CountFiles + 1 FileName = Dir Wend Clean = CountFiles End Function "jt46" wrote: Does anyone knows how to write a simple code to delete a file or files by their file extension? Thanks in advance. John -- jt46 ------------------------------------------------------------------------ jt46's Profile: http://www.excelforum.com/member.php...o&userid=15154 View this thread: http://www.excelforum.com/showthread...hreadid=268917 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Determine Excel file version with no file extension. | Excel Discussion (Misc queries) | |||
file format or file extension is not valid...error message | Excel Discussion (Misc queries) | |||
Additional file with no extension created during File Save As proc | Excel Discussion (Misc queries) | |||
how i open a file XLS extension[ exelspreadsheet file] | Excel Worksheet Functions | |||
I need to download an exel spreadsheet file. (file extension :xls) | Excel Discussion (Misc queries) |