Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I would like to delete all files in a folder where the file name starts
with a number. So it would delete 33.xls but not delete Mike.xls The file in question is C:\Temp TIA! - Mike *** Sent via Developersdex http://www.developersdex.com *** |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Mike,
Set a reference to 'Microsoft Scripting Runtime' & the following should work. Public Sub DeleteAllNumericStarts() Dim fso As New FileSystemObject Dim fsoFile As File For Each fsoFile In fso.GetFolder("C:\temp") If Asc(Left(fsoFile.Name, 1)) = 48 And Asc(Left(fsoFile.Name, 1)) <= 57 Then fsoFile.Delete Next fsoFile End Sub Regards, Chris. -- Chris Marlow MCSD.NET, Microsoft Office XP Master "Michael Smith" wrote: I would like to delete all files in a folder where the file name starts with a number. So it would delete 33.xls but not delete Mike.xls The file in question is C:\Temp TIA! - Mike *** Sent via Developersdex http://www.developersdex.com *** |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Correction -
Missed .Files on the For ... Each Public Sub DeleteAllNumericStarts() Dim fso As New FileSystemObject Dim fsoFile As File For Each fsoFile In fso.GetFolder("C:\temp").Files If Asc(Left(fsoFile.Name, 1)) = 48 And Asc(Left(fsoFile.Name, 1)) <= 57 Then fsoFile.Delete Next fsoFile End Sub -- Chris Marlow MCSD.NET, Microsoft Office XP Master "Chris Marlow" wrote: Mike, Set a reference to 'Microsoft Scripting Runtime' & the following should work. Public Sub DeleteAllNumericStarts() Dim fso As New FileSystemObject Dim fsoFile As File For Each fsoFile In fso.GetFolder("C:\temp") If Asc(Left(fsoFile.Name, 1)) = 48 And Asc(Left(fsoFile.Name, 1)) <= 57 Then fsoFile.Delete Next fsoFile End Sub Regards, Chris. -- Chris Marlow MCSD.NET, Microsoft Office XP Master "Michael Smith" wrote: I would like to delete all files in a folder where the file name starts with a number. So it would delete 33.xls but not delete Mike.xls The file in question is C:\Temp TIA! - Mike *** Sent via Developersdex http://www.developersdex.com *** |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That's it...thanks!...would have never thought of that.
*** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel E-2007 starts, but Installer also starts 3 times??? | Setting up and Configuration of Excel | |||
opening a file in Excel starts application but dose not open file | Excel Discussion (Misc queries) | |||
Zero starts of a number | Excel Worksheet Functions | |||
Delete row if cell starts with ........... | New Users to Excel | |||
If (starts with ', then delete the ') | Excel Programming |