Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# how to delete a file

File.Delete(@"C:TempDataAuthors.txt");
Comment

find and delete files c#

string rootFolderPath = @"C:SomeFolderAnotherFolderFolderCOntainingThingsToDelete";
string filesToDelete = @"*DeleteMe*.doc";   // Only delete DOC files containing "DeleteMe" in their filenames
string[] fileList = System.IO.Directory.GetFiles(rootFolderPath, filesToDelete);
foreach(string file in fileList)
{
    System.Diagnostics.Debug.WriteLine(file + "will be deleted");
//  System.IO.File.Delete(file);
}
Comment

c# delete files

// Simple synchronous file deletion operations with no user interface.
// To run this sample, create the following files on your drive:
// C:UsersPublicDeleteTest	est1.txt
// C:UsersPublicDeleteTest	est2.txt
// C:UsersPublicDeleteTestSubDir	est2.txt

public class SimpleFileDelete
{
    static void Main()
    {
        // Delete a file by using File class static method...
        if(System.IO.File.Exists(@"C:UsersPublicDeleteTest	est.txt"))
        {
            // Use a try block to catch IOExceptions, to
            // handle the case of the file already being
            // opened by another process.
            try
            {
                System.IO.File.Delete(@"C:UsersPublicDeleteTest	est.txt");
            }
            catch (System.IO.IOException e)
            {
                Console.WriteLine(e.Message);
                return;
            }
        }

        // ...or by using FileInfo instance method.
        System.IO.FileInfo fi = new System.IO.FileInfo(@"C:UsersPublicDeleteTest	est2.txt");
        try
        {
            fi.Delete();
        }
        catch (System.IO.IOException e)
        {
            Console.WriteLine(e.Message);
        }

        // Delete a directory. Must be writable or empty.
        try
        {
            System.IO.Directory.Delete(@"C:UsersPublicDeleteTest");
        }
        catch (System.IO.IOException e)
        {
            Console.WriteLine(e.Message);
        }
        // Delete a directory and all subdirectories with Directory static method...
        if(System.IO.Directory.Exists(@"C:UsersPublicDeleteTest"))
        {
            try
            {
                System.IO.Directory.Delete(@"C:UsersPublicDeleteTest", true);
            }

            catch (System.IO.IOException e)
            {
                Console.WriteLine(e.Message);
            }
        }

        // ...or with DirectoryInfo instance method.
        System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(@"C:UsersPublicpublic");
        // Delete this dir and all subdirs.
        try
        {
            di.Delete(true);
        }
        catch (System.IO.IOException e)
        {
            Console.WriteLine(e.Message);
        }
    }
}
Comment

How to delete File in c#

string gpath;

        string path=@"c:UsersAdamDesktop";

        string name="file";

        string f="";

        int i=0;

        string ext=".txt";

        while(File.Exists(path + name + f + ext))
        {
            i++;

            f = i.ToString();
        }

        gpath = path + name + f + ext;

        button2.Enabled = true;

        File.Create(gpath);

        File.Delete(gpath);//why there is an Error??
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# remove all null from list 
Csharp :: sconvert string to title case + C3 
Csharp :: setactive unity 
Csharp :: C#: convert array of integers to comma separated string 
Csharp :: create folder in appdata c# 
Csharp :: string to enum c# 
Csharp :: set text in center wpf 
Csharp :: how to get all files from folder and subfolders in c# 
Csharp :: change textbox location C# 
Csharp :: c# remove accents 
Csharp :: isprime c# 
Csharp :: mouselook script unity 
Csharp :: unity mouse wheel 
Csharp :: c# unity camera follow player horizontal axis 
Csharp :: c# convert string to char array 
Csharp :: .net create ienumerable of strings 
Csharp :: messagebox.show c# error 
Csharp :: wpf fixed size window 
Csharp :: assign datasource to dropdownlist in c# 
Csharp :: unity change tag of go 
Csharp :: wpf load file content 
Csharp :: how to make a quit button in unity 
Csharp :: c# square every digit of a number 
Csharp :: remove backcolor c# 
Csharp :: new parameterized thread c# 
Csharp :: visual studio windows form exit button 
Csharp :: change picturebox image c# 
Csharp :: unity set sprite transparency 
Csharp :: cshtml foreach 
Csharp :: unity get child 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =