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#: casting string to enum object 
Csharp :: euler angles to quaternion unity 
Csharp :: run async method parallel c# 
Csharp :: get index of item unity 
Csharp :: how to get the index of an element in a list in unity 5 
Csharp :: c# optional parameters using 
Csharp :: run as administrator vs 2019 
Csharp :: how to make a enemy in unity 
Csharp :: unity error cs1656 
Csharp :: how do i repeat a button on visual studio code 
Csharp :: c# MD5.Create returning nul 
Csharp :: wpf scoll to on new item datagrtid 
Csharp :: string to date 
Html :: html meta redirect 
Html :: html5 template 
Html :: align eliment in center of row bootstrap 
Html :: connecting metamask to binance smart chain 
Html :: how to remove download option from video tag in html 
Html :: link email anchor to open up users email address 
Html :: target _blank 
Html :: add favicon to html 
Html :: bootstrap 5 text bold 
Html :: how to center link in html 
Html :: html power 
Html :: twig foreach key value 
Html :: font awesome 5 pro 
Html :: target blank rel 
Html :: how to insert degree symbol in html 
Html :: rel noopener noreferrer nofollow 
Html :: how to put a table in the middle of a div in html 
ADD CONTENT
Topic
Content
Source link
Name
2+9 =