Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Determine Excel file version with no file extension. tjlumpkin Excel Discussion (Misc queries) 2 July 23rd 09 06:59 AM
file format or file extension is not valid...error message Ballun Excel Discussion (Misc queries) 0 May 7th 09 09:06 PM
Additional file with no extension created during File Save As proc Peter Rooney Excel Discussion (Misc queries) 2 August 11th 05 02:48 PM
how i open a file XLS extension[ exelspreadsheet file] how to open a excel spreedsheet file Excel Worksheet Functions 1 July 25th 05 01:48 PM
I need to download an exel spreadsheet file. (file extension :xls) buckrogers Excel Discussion (Misc queries) 2 December 8th 04 11:08 PM


All times are GMT +1. The time now is 08:19 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"