DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Sep 2009
    Location
    caracas
    Posts
    7

    Deleting a set of file

    Hi, I want to delete a set of files but in an efficient way.
    I have an array of string called filesToUse that contains the list of files names to keep in disk. Then, I search in my folder all files but I need check every files do not match with any element in my array. By example:
    Code:
    foreach(string sFile in System.IO.Directory.GetFiles("C:\\*.bmp"))
    {
        bool flag = false;
        foreach (string s in filesToUse)
            if (s.Equals(sFile))
              flag = true;
        if(flag) System.IO.File.Delete(sFile); //anyone of these are in filesToUse
    }
    I think that both foreach is unnecessary, any better solution without use 2 for's?
    Thanks in advance

    esmitt

  2. #2
    Join Date
    Oct 2008
    Posts
    141

    forfiles.exe

    hi there,

    this is not a dotnet solution, but deleting files is recommended with forfiles.exe utility.

    here is information about forfiles.exe --> http://www.google.com/#sclient=psy&h...50e40e87b009cf

    best regards,

    tonci korsano

Similar Threads

  1. Create XML file from a string in SQL server 2000
    By shan_2007 in forum Database
    Replies: 0
    Last Post: 12-11-2007, 06:34 AM
  2. Replies: 0
    Last Post: 09-22-2007, 06:54 AM
  3. Deleting a file using Windows Service
    By adjones1980 in forum .NET
    Replies: 2
    Last Post: 07-26-2007, 05:53 PM
  4. How long before the next version??
    By _CAG in forum .NET
    Replies: 146
    Last Post: 08-12-2002, 10:40 PM
  5. File uploading / objFile.Write problem
    By Tomer Cagan in forum ASP.NET
    Replies: 1
    Last Post: 07-24-2001, 09:01 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links