deleting *.doc in asp.net

S

Stimp

I want to delete all my .doc files in a specific directory.

I tried to do this using the File.Delete method, but it doesn't allow
"*.doc" paths.

So I tried the following code:

Dim objFSO = Server.CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile(Server.MapPath("*.doc"))

and it works on my local pc, but I doubt I should be using classic asp
components with asp.net.. what was is the equivalent function in
asp.net?

Cheers.
 
J

John Timney \( MVP \)

off the top of my head try something like this :

DirectoryInfo dir = new DirectoryInfo(@"c:\tmp");
FileInfo[] docfiles = dir.GetFiles("*.doc");

Foreach( FileInfo f in docfiles)
{
File.Delete( f.Name)
}

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director
 
S

Stimp

off the top of my head try something like this :

DirectoryInfo dir = new DirectoryInfo(@"c:\tmp");
FileInfo[] docfiles = dir.GetFiles("*.doc");

Foreach( FileInfo f in docfiles)
{
File.Delete( f.Name)
}

nope doesn't seem to work.

Dim dir As DirectoryInfo = New
DirectoryInfo(Server.MapPath("mydirectory"))

Dim docfiles() As FileInfo = dir.GetFiles("*.doc")

Dim f As FileInfo

For Each f In docfiles
File.Delete(f.Name)
Next
 
S

Stimp

off the top of my head try something like this :

DirectoryInfo dir = new DirectoryInfo(@"c:\tmp");
FileInfo[] docfiles = dir.GetFiles("*.doc");

Foreach( FileInfo f in docfiles)
{
File.Delete( f.Name)
}

actually I just got it working... the problem was with the path used in
the File.Delete section

Thanks!
 
J

John Timney \( MVP \)

Sorry - as I said off the top of my head. Glad to have helped.

--
Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

Stimp said:
off the top of my head try something like this :

DirectoryInfo dir = new DirectoryInfo(@"c:\tmp");
FileInfo[] docfiles = dir.GetFiles("*.doc");

Foreach( FileInfo f in docfiles)
{
File.Delete( f.Name)
}

actually I just got it working... the problem was with the path used in
the File.Delete section

Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top