473,467 Members | 1,554 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

deleting folder and entire contents

anfetienne
424 Contributor
Hi,

I've tried so many codes to delete folders that has other folders and files within them but no joy as to finding one that works. I get alot of permission denied....don't know how to get around this

Any suggestions on one that does work?
Jun 7 '09 #1
1 1161
Atli
5,058 Recognized Expert Expert
Hi.

If you want to completely remove a non-empty directory, you must first remove all files and sub-directories from within it.

Best way to deal with tasks like that is probably a recursive function:
(in pseudocode)
Expand|Select|Wrap|Line Numbers
  1. function deleteDirectory(pathToDirector)
  2.     foreach fileInDirectory
  3.         unlink(fileInDirectory)
  4.  
  5.     foreach dirInDirectory
  6.         deleteDirectory(dirInDirectory)
  7.  
  8.     rmdir(pathToDirectory)
I suggest reading up on the readdir, unlink and rmdir functions.

And you will of course have to have full permission on the directory and all it's files and sub-directories.
Jun 7 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Chris | last post by:
Hi, Not sure if this is the right forum, but hopefully someone can help me. I am creating something for our intranet and i want to list the files and folders of a directory, i found some code...
5
by: Dan | last post by:
I am working on a C# ASP.NET project where I need to allow the user to browse to a folder. The only way I see how to do this is use <input type=file>. But this makes the user select a file and...
2
by: kevin | last post by:
Greetings. I am well aware that visual studio.net (vb.net) has the option of using their custom installer software, but i insist on creating my own. I am relatively new, and so i am looking...
2
by: Bernie Yaeger | last post by:
I've asked this question before but now I need something different: I need to select files using openfiledialog, which is easy enough. But I want to select a file or files (multiselect) and also...
0
by: steven.shannon | last post by:
Hello, I'm writing an app that involves deleting all the items in a specified Outlook folder regardless of item type (i.e. Contacts, Tasks, etc.). This code was ported from VBA where it worked...
1
by: Lee | last post by:
Hi, when deleting a directory using;- string dir = "whatever"; Directory.Delete(dir); it fails if files/directories exist within the directory being deleted. is there an easy way of...
3
by: Madingo | last post by:
I need to create a routine that will email all contents of a folder. But The number of files and extensions will be different. Some will have .doc and .xls. Is there a way to email the contents...
3
by: Kimera.Kimera | last post by:
I'm trying to write a program in VB.net 2003 that basically deletes all files, folders, sub-folders and sub-sub folders (etc). The program is simply for deleting the Windows/Temp folder contents,...
0
by: rahuldhammy | last post by:
I am implementing a personalization(customizing the contents of the web site according to the user choice)in asp.net web site.For this i have to delete modify some files in my App_Themes folder.I am...
1
by: chazzy69 | last post by:
Hi i know that u can delete and entire field from a table i.e. DELETE FROM table WHERE bla="bla" But what i want to do is only delete the stuff contained in one cell of the field i.e. rather...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.