473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

working with sytem.io

ZR
Hi,
I am trying to delete multiple files in a particular directory.
The code will like this
\\\
Dim s As String
For Each s in Directory.GetFiles(...)
system.io.file.delete(s)
Next s
///

Is there a method that would allow me delete more than one file at a time?

for instance Delete "*.txt"
Nov 20 '05 #1
6 1596
"ZR" <zv******@hotmail.donotspam> schrieb
[nothing new]


It is sufficient to post the question once.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2
ZR
I thought you might have an answer to the question.
"Armin Zingler" <az*******@freenet.de> wrote in message
news:uB**************@TK2MSFTNGP11.phx.gbl...
"ZR" <zv******@hotmail.donotspam> schrieb
[nothing new]


It is sufficient to post the question once.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
* "ZR" <zv******@hotmail.donotspam> scripsit:
I am trying to delete multiple files in a particular directory.
The code will like this
\\\
Dim s As String
For Each s in Directory.GetFiles(...)
system.io.file.delete(s)
Next s
///

Is there a method that would allow me delete more than one file at a time?


AFAIK there is no easier way to do what you want. You can use
'Directory.Delete' to delete a whole directory.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
Nov 20 '05 #4
ZR
thanks alot for your help
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:bo*************@ID-208219.news.uni-berlin.de...
* "ZR" <zv******@hotmail.donotspam> scripsit:
I am trying to delete multiple files in a particular directory.
The code will like this
\\\
Dim s As String
For Each s in Directory.GetFiles(...)
system.io.file.delete(s)
Next s
///

Is there a method that would allow me delete more than one file at a
time?
AFAIK there is no easier way to do what you want. You can use
'Directory.Delete' to delete a whole directory.

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>

Nov 20 '05 #5
I have some code I will give you that does recursive directory and file
searches. You can pass the function a wildcard.

'*******************************
'*
'* Shawn Shelton
'* This will search directories for files and directories.
'* May be recursive if told to.
'* Use wildcards for searching such as * or .exe
'*
Option Explicit On
Option Strict On
Imports System
Imports System.IO
Imports System.Collections
Module Searcher
Public Sub SearchDirectoryForFiles(ByVal dirlist As Stack, ByVal
searchPath As String, ByVal RecurseDirs As Boolean)
' Split searchPath into a directory and a wildcard specification.
'
Dim directoryPath As String = Path.GetDirectoryName(searchPath)
Dim search As String = Path.GetFileName(searchPath)
Dim dir As New DirectoryInfo(directoryPath)
If directoryPath Is Nothing Or search Is Nothing Then
Return
End If
Dim f As FileInfo
Try
For Each f In dir.GetFiles(search)
dirlist.Push(f.FullName)
Next
Catch e As UnauthorizedAccessException
Return
Catch e As DirectoryNotFoundException
Return
End Try

' Now that you have finished the files in this directory, recurse for
' each subdirectory.
If RecurseDirs = True Then
Dim directories As String() = Directory.GetDirectories(directoryPath)
Dim d As String
For Each d In directories
SearchDirectoryForFiles(dirlist, Path.Combine(d, search), True)
Next d
End If
End Sub

Public Sub SearchDirectoryForDirectories(ByVal dirList As Stack, ByVal
searchPath As String)
Dim directoryPath As String = Path.GetDirectoryName(searchPath)
Dim directories As String() = Directory.GetDirectories(directoryPath)
Dim d As String
For Each d In directories
dirList.Push(d)
SearchDirectoryForDirectories(dirList, d & "\")
Next d
End Sub

End Module
****************************

Call it like this:

dim dirlist as stack
dim x as string
SearchDirectoryForFiles(DirList, "c:\winnt\*.txt", False)
If DirList.Count > 0 Then
For Each x In DirList
SetAttr(x, FileAttribute.Normal)
File.Delete(x)
Next
End If
ZR wrote:
Hi,
I am trying to delete multiple files in a particular directory.
The code will like this
\\\
Dim s As String
For Each s in Directory.GetFiles(...)
system.io.file.delete(s)
Next s
///

Is there a method that would allow me delete more than one file at a time?

for instance Delete "*.txt"


Nov 20 '05 #6
ZR
Thanks alot for your help
"Shawn D Shelton" <sh******@isu.edu> wrote in message
news:uB***************@TK2MSFTNGP10.phx.gbl...
I have some code I will give you that does recursive directory and file
searches. You can pass the function a wildcard.

'*******************************
'*
'* Shawn Shelton
'* This will search directories for files and directories.
'* May be recursive if told to.
'* Use wildcards for searching such as * or .exe
'*
Option Explicit On
Option Strict On
Imports System
Imports System.IO
Imports System.Collections
Module Searcher
Public Sub SearchDirectoryForFiles(ByVal dirlist As Stack, ByVal
searchPath As String, ByVal RecurseDirs As Boolean)
' Split searchPath into a directory and a wildcard specification.
'
Dim directoryPath As String = Path.GetDirectoryName(searchPath)
Dim search As String = Path.GetFileName(searchPath)
Dim dir As New DirectoryInfo(directoryPath)
If directoryPath Is Nothing Or search Is Nothing Then
Return
End If
Dim f As FileInfo
Try
For Each f In dir.GetFiles(search)
dirlist.Push(f.FullName)
Next
Catch e As UnauthorizedAccessException
Return
Catch e As DirectoryNotFoundException
Return
End Try

' Now that you have finished the files in this directory, recurse for
' each subdirectory.
If RecurseDirs = True Then
Dim directories As String() = Directory.GetDirectories(directoryPath)
Dim d As String
For Each d In directories
SearchDirectoryForFiles(dirlist, Path.Combine(d, search), True)
Next d
End If
End Sub

Public Sub SearchDirectoryForDirectories(ByVal dirList As Stack, ByVal
searchPath As String)
Dim directoryPath As String = Path.GetDirectoryName(searchPath)
Dim directories As String() = Directory.GetDirectories(directoryPath)
Dim d As String
For Each d In directories
dirList.Push(d)
SearchDirectoryForDirectories(dirList, d & "\")
Next d
End Sub

End Module
****************************

Call it like this:

dim dirlist as stack
dim x as string
SearchDirectoryForFiles(DirList, "c:\winnt\*.txt", False)
If DirList.Count > 0 Then
For Each x In DirList
SetAttr(x, FileAttribute.Normal)
File.Delete(x)
Next
End If
ZR wrote:
Hi,
I am trying to delete multiple files in a particular directory.
The code will like this
\\\
Dim s As String
For Each s in Directory.GetFiles(...)
system.io.file.delete(s)
Next s
///

Is there a method that would allow me delete more than one file at a time?
for instance Delete "*.txt"

Nov 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Gary | last post by:
I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)"); This is not working ..what could be the...
1
by: Yoshitha | last post by:
Hi, My asp.net application is working fine in my system. when i'm executing the same application in server am not getting the controls in my webform. for e.g. in default page i've placed...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
4
by: Joshua Campbell | last post by:
I am working on an application that needs to parse out data that has been copied into the clipboard. My first questions are how can I detect if the clipboard is empty, and how can I empty the...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
1
by: John | last post by:
Is there a way to place sytem icons suchs as the ones use in a message bos (i.e exclamiation, information, question, etc) on a form. Is there a way to do it with =out a picturebox and still...
2
by: PR | last post by:
Hello, I have a bunch of textboxes on my form, and I would very much like it if their text could be automatically selected when each one is entered. I've tried code like this: Private Sub...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.