Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

c# how to delete a file

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

How to delete folder with files on c#

Directory.Delete(@"folderPath", true);
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 :: check if mouse is in frame unity 
Csharp :: defining vectors in c# 
Csharp :: new datetime c# 
Csharp :: Commenting on C# 
Csharp :: c# null conditional operator if statement 
Csharp :: c# sftp 
Csharp :: quaternion rotation unity 
Csharp :: interface property implementation c# 
Csharp :: longest substring without repeating characters 
Csharp :: concat arrays .net 
Csharp :: enum in c# 
Csharp :: audiosource unity 
Csharp :: c# add strings 
Csharp :: c# create log file 
Csharp :: hide numericUpDown arrows 
Csharp :: entity framework with query C# 
Csharp :: checkbox in c# 
Csharp :: c# divide two integers get float 
Csharp :: unity auto scroll 
Csharp :: c# usermanager update user 
Csharp :: clickable table row asp.net core 
Csharp :: cdn providers 
Csharp :: unity reload active scene 
Csharp :: remove string inside curly braces C# 
Csharp :: convert string into float C# 
Csharp :: c# lambda group by multiple columns 
Csharp :: #grid 
Csharp :: c# builder pattern fluent example 
Csharp :: write last line txt file c# 
Csharp :: c# list contains null 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =