Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Delete file if it starts with a number

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Delete file if it starts with a number

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Delete file if it starts with a number

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 77
Default Delete file if it starts with a number

That's it...thanks!...would have never thought of that.

*** Sent via Developersdex http://www.developersdex.com ***
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
Excel E-2007 starts, but Installer also starts 3 times??? Thanks for the Great Tip Setting up and Configuration of Excel 0 January 24th 10 03:21 AM
opening a file in Excel starts application but dose not open file Bob Shelton Excel Discussion (Misc queries) 1 July 2nd 08 07:51 PM
Zero starts of a number Lisa Excel Worksheet Functions 5 June 9th 06 09:48 PM
Delete row if cell starts with ........... mohd21uk via OfficeKB.com New Users to Excel 2 May 15th 06 05:50 PM
If (starts with ', then delete the ') [email protected] Excel Programming 9 December 17th 04 06:48 PM


All times are GMT +1. The time now is 11:36 PM.

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

About Us

"It's about Microsoft Excel"