474,057 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I delete multiple files?

Hi!

How do I delete multiple files in C#? I would like the specific code.

Thanks!

Matt
May 22 '06 #1
10 14568
Mateusz Rajca <Ma**********@d iscussions.micr osoft.com> wrote:
How do I delete multiple files in C#? I would like the specific code.


Use File.Delete() multiple times.

-- Barry

--
http://barrkel.blogspot.com/
May 22 '06 #2
But this is a Cookies cleaner. I dont know each files filename. I would like
to just delete all files from the directory.

"Barry Kelly" wrote:
Mateusz Rajca <Ma**********@d iscussions.micr osoft.com> wrote:
How do I delete multiple files in C#? I would like the specific code.


Use File.Delete() multiple times.

-- Barry

--
http://barrkel.blogspot.com/

May 22 '06 #3
Directory.GetFi les is your friend

"Mateusz Rajca" <Ma**********@d iscussions.micr osoft.com> wrote in message
news:1A******** *************** ***********@mic rosoft.com...
But this is a Cookies cleaner. I dont know each files filename. I would
like
to just delete all files from the directory.

"Barry Kelly" wrote:
Mateusz Rajca <Ma**********@d iscussions.micr osoft.com> wrote:
> How do I delete multiple files in C#? I would like the specific code.


Use File.Delete() multiple times.

-- Barry

--
http://barrkel.blogspot.com/

May 22 '06 #4
Mateusz Rajca <Ma**********@d iscussions.micr osoft.com> wrote:
But this is a Cookies cleaner. I dont know each files filename. I would like
to just delete all files from the directory.


Use a loop.

foreach (string fileName in Directory.GetFi les("path/to/files"))
File.Delete(fil eName);

-- Barry

--
http://barrkel.blogspot.com/
May 22 '06 #5
Thanks but i get an error that it cannot remove index.dat. How can i skip
that file?

Matt

"Barry Kelly" wrote:
Mateusz Rajca <Ma**********@d iscussions.micr osoft.com> wrote:
But this is a Cookies cleaner. I dont know each files filename. I would like
to just delete all files from the directory.


Use a loop.

foreach (string fileName in Directory.GetFi les("path/to/files"))
File.Delete(fil eName);

-- Barry

--
http://barrkel.blogspot.com/

May 22 '06 #6
omg, man!

foreach (string fileName in Directory.GetFi les("path/to/files"))
{
if (Path.GetFileNa me(fileName) != "index.dat" )
File.Delete(fil eName);
}

that's it, really worth waiting for someone to answer instead of turning the
brain on!

"Mateusz Rajca" <Ma**********@d iscussions.micr osoft.com> wrote in message
news:5F******** *************** ***********@mic rosoft.com...
Thanks but i get an error that it cannot remove index.dat. How can i skip
that file?

Matt

"Barry Kelly" wrote:
Mateusz Rajca <Ma**********@d iscussions.micr osoft.com> wrote:
> But this is a Cookies cleaner. I dont know each files filename. I would
> like
> to just delete all files from the directory.


Use a loop.

foreach (string fileName in Directory.GetFi les("path/to/files"))
File.Delete(fil eName);

-- Barry

--
http://barrkel.blogspot.com/

May 22 '06 #7
Thats not what I want. I want the app to SKIP the file.

Matt

"Lebesgue" wrote:
omg, man!

foreach (string fileName in Directory.GetFi les("path/to/files"))
{
if (Path.GetFileNa me(fileName) != "index.dat" )
File.Delete(fil eName);
}

that's it, really worth waiting for someone to answer instead of turning the
brain on!

"Mateusz Rajca" <Ma**********@d iscussions.micr osoft.com> wrote in message
news:5F******** *************** ***********@mic rosoft.com...
Thanks but i get an error that it cannot remove index.dat. How can i skip
that file?

Matt

"Barry Kelly" wrote:
Mateusz Rajca <Ma**********@d iscussions.micr osoft.com> wrote:

> But this is a Cookies cleaner. I dont know each files filename. I would
> like
> to just delete all files from the directory.

Use a loop.

foreach (string fileName in Directory.GetFi les("path/to/files"))
File.Delete(fil eName);

-- Barry

--
http://barrkel.blogspot.com/


May 23 '06 #8
Mateusz Rajca <Ma**********@d iscussions.micr osoft.com> wrote:
Thats not what I want. I want the app to SKIP the file.


Why don't you hire a programmer to write the code?

-- Barry

--
http://barrkel.blogspot.com/
May 23 '06 #9
The App skips the file

"Mateusz Rajca" <Ma**********@d iscussions.micr osoft.com> wrote in message
news:6E******** *************** ***********@mic rosoft.com...
Thats not what I want. I want the app to SKIP the file.

Matt

"Lebesgue" wrote:
omg, man!

foreach (string fileName in Directory.GetFi les("path/to/files"))
{
if (Path.GetFileNa me(fileName) != "index.dat" )
File.Delete(fil eName);
}

that's it, really worth waiting for someone to answer instead of turning
the
brain on!

"Mateusz Rajca" <Ma**********@d iscussions.micr osoft.com> wrote in message
news:5F******** *************** ***********@mic rosoft.com...
> Thanks but i get an error that it cannot remove index.dat. How can i
> skip
> that file?
>
> Matt
>
> "Barry Kelly" wrote:
>
>> Mateusz Rajca <Ma**********@d iscussions.micr osoft.com> wrote:
>>
>> > But this is a Cookies cleaner. I dont know each files filename. I
>> > would
>> > like
>> > to just delete all files from the directory.
>>
>> Use a loop.
>>
>> foreach (string fileName in Directory.GetFi les("path/to/files"))
>> File.Delete(fil eName);
>>
>> -- Barry
>>
>> --
>> http://barrkel.blogspot.com/
>>


May 23 '06 #10

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

Similar topics

0
2429
by: NIck | last post by:
Hello all I try to do a multiple delete of files through FileSystemObject, but after deleting the first file, ASP gives me a "Permission denied" error. Below you see my code: Set fso = CreateObject("Scripting.FileSystemObject") For Each Item in Request.Form("filename")
4
11914
by: Shyguy | last post by:
I have a database that backs up critical tables to a database, named Backup with the date, daily. I can't figure out how to delete these databases programmatically, say when they are 5 days old or older. I was able to figure out how to delete them if they are 5 days older then current date but the weekends and holiday, etc. leave some undeleted. Any help will be greatly appreciated, ShyGuy
1
2441
by: Drew | last post by:
Hi all I'm fairly new to python so please forgive my lack of comprehension of the obvious. I'm writing a script to ftp files to a server. This script will run weekly. Part of the script first deletes the previous weeks files. The problem is I'm never sure of the exact number and full name of the files that need to be deleted. All the files start with the same string but have different extensions (eg drew.1 drew.2 drew.tmp drew.hlp). So...
6
4316
by: jefftyzzer | last post by:
Friends: Let's say I'd like perform a delete, but before I delete, I'd like to export the target rows. I could use an export whose SELECT clause references the OLD TABLE of a DELETE, but the issue is I'm deleting the table in chunks, like so: WHILE (V_NO_DATA = 0) DO DELETE FROM
4
2227
by: - HAL9000 | last post by:
When un-installing an application... Is it normal practice to write a special program that erases all the files and folders for all the users of an application that reads and writes to SpecialFolder.ApplicationData (C:\Documents and Settings\Username\Application Data) ? Or, is there some way to get the ms installer to do this for you? Is there some way to use Application.UserAppDataPath to ease finding
10
12249
by: Joah Senegal | last post by:
Hello all, I want something that should be realy really simple.... but I dont get it.. searched google and stuf, but found nothing useful. I;m opening a txt-file with a fstream. Now I want to make a function that looks like Removeline(int Linenumber); But I can;t get it working.. anybody has anything helpfull? if anybody can help me that would be great :D
2
24133
by: Thomas Bauer | last post by:
Hello, Call DeleteFiles bgW_DeleteFilesProcess = new DeleteFiles(); bgW_DeleteFilesProcess.RunAsync( folder, 5, "*.txt", new RunWorkerCompletedEventHandler( RunWorkerCompleted_DeleteFiles_TXT ) ); I delete all files, which older than 5 days and I use a background thread.
0
2968
by: wolfsbane | last post by:
Alright, here it is I am trying to write a win32 app in VB 2005 to clean up user's profiles. everything works correctly except for the Delete("directory", True) statement. I get a System.IO.DirectoryNotFoundException: Could not find a part of the path. Then it gives me a random file name from the UserProfile\Local Settings\Temporary Internet Files\Content.IE5\SomeRandomFolder. This is absolutley driving me nuts. So I am gonn give you a basic...
1
5746
by: achotto | last post by:
hi, i try to upload a multiple image files. after that i will rename the files name. the problem is when i upload a 2 or more same files name exp-goal.jpg, it will return "files already exist". ok this is my codes, Set Upload = Server.CreateObject("Persits.Upload.1") Count = Upload.Save("d:\cmsupload\cimg\") for each File in upload.Files ' '...sme operation here..
0
10374
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
12084
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
11163
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
10357
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8743
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6686
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4960
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
4000
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.