C# Forms read textBox1 all lines and delete given paths?Replace Line Breaks in a String C#Best way to parse command line arguments in C#?C# getting the path of %AppData%How to loop through all enum values in C#?How to delete all files and folders in a directory?Reading error C#Encrypting/decrypting a file line by line?C# method failing to function for no known reasonArray of textbox and labels how to get value in submit method in c#c# foreach loop for downloading image just works once

Is a diamond sword feasible?

Was there ever any real use for a 6800-based Apple I?

How to make a Lich look like a human without magic in 5e?

Is there enough time to Planar Bind a creature conjured by a one hour duration spell?

How does Howard Stark know this?

Is there any evidence to support the claim that the United States was "suckered into WW1" by Zionists, made by Benjamin Freedman in his 1961 speech?

Make all the squares explode

What food production methods would allow a metropolis like New York to become self sufficient

The lexical root of the past tense forms differs from the lexical root of the infinitive form

Why in a Ethernet LAN, a packet sniffer can obtain all packets sent over the LAN?

What are some possible reasons that a father's name is missing from a birth certificate - England?

What is the significance of 4200 BCE in context of farming replacing foraging in Europe?

Ex-manager wants to stay in touch, I don't want to

What did Rocket give Hawkeye in "Avengers: Endgame"?

How are Core iX names like Core i5, i7 related to Haswell, Ivy Bridge?

On studying Computer Science vs. Software Engineering to become a proficient coder

How could we transfer large amounts of energy sourced in space to Earth?

Renting a house to a graduate student in my department

Why was the Ancient One so hesitant to teach Dr. Strange the art of sorcery?

How old is Captain America at the end of "Avengers: Endgame"?

On what legal basis did the UK remove the 'European Union' from its passport?

Cropping a message using array splits

International Code of Ethics for order of co-authors in research papers

the lecture's place or where the lecture takes place



C# Forms read textBox1 all lines and delete given paths?


Replace Line Breaks in a String C#Best way to parse command line arguments in C#?C# getting the path of %AppData%How to loop through all enum values in C#?How to delete all files and folders in a directory?Reading error C#Encrypting/decrypting a file line by line?C# method failing to function for no known reasonArray of textbox and labels how to get value in submit method in c#c# foreach loop for downloading image just works once






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-1















Good day!



I'm trying to create a C # Forms app where user chooses directories with FolderDialog and paths are saved in list.txt file after read by textBox1.
In list.txt user can add and delete path.



code snippet:



private void Form1_Load(object sender, EventArgs e)

textBox1.Lines = System.IO.File.ReadAllLines(fileName);

string fileName = Environment.CurrentDirectory + @"/etc/list.txt";

private void LoadTextboxes()

string[] loadedLines = System.IO.File.ReadAllLines(Environment.CurrentDirectory + @"/etc/list.txt");

int index = 0;

int n = int.Parse(loadedLines[index]);
string[] lines = new string[n];
Array.Copy(loadedLines, index + 1, lines, 0, n);
textBox1.Lines = lines;

private void DeleteFilesFromDirectory(string directoryPath)

DirectoryInfo d = new DirectoryInfo(directoryPath);

foreach (FileInfo fi in d.GetFiles())

fi.Delete();


foreach (DirectoryInfo di in d.GetDirectories())

DeleteFilesFromDirectory(di.FullName);

di.Delete();



private void button1_Del(object sender, EventArgs e)

DeleteFilesFromDirectory(textBox1.Text);



list.txt format:



C:/downloads
F:/doc/scan
D:/etc


t is important to delete only the sub folders and files but root folders must remain.
So far I have been done with my weak knowledge of c# and and now I'm stuck for a long time.
DeleteFilesFromDirectory only deletes the first line of textBox1.



How to make DeleteFilesFromDirectory read and delete all lines from textBox1?










share|improve this question
























  • So the root folder is downloads,doc,etc ?

    – Marios Nikolaou
    Mar 23 at 11:10











  • If given path is F:/doc/scan, then need to be wiped everything under folder scan, but leave root folder scan empty

    – Uldis
    Mar 23 at 11:52


















-1















Good day!



I'm trying to create a C # Forms app where user chooses directories with FolderDialog and paths are saved in list.txt file after read by textBox1.
In list.txt user can add and delete path.



code snippet:



private void Form1_Load(object sender, EventArgs e)

textBox1.Lines = System.IO.File.ReadAllLines(fileName);

string fileName = Environment.CurrentDirectory + @"/etc/list.txt";

private void LoadTextboxes()

string[] loadedLines = System.IO.File.ReadAllLines(Environment.CurrentDirectory + @"/etc/list.txt");

int index = 0;

int n = int.Parse(loadedLines[index]);
string[] lines = new string[n];
Array.Copy(loadedLines, index + 1, lines, 0, n);
textBox1.Lines = lines;

private void DeleteFilesFromDirectory(string directoryPath)

DirectoryInfo d = new DirectoryInfo(directoryPath);

foreach (FileInfo fi in d.GetFiles())

fi.Delete();


foreach (DirectoryInfo di in d.GetDirectories())

DeleteFilesFromDirectory(di.FullName);

di.Delete();



private void button1_Del(object sender, EventArgs e)

DeleteFilesFromDirectory(textBox1.Text);



list.txt format:



C:/downloads
F:/doc/scan
D:/etc


t is important to delete only the sub folders and files but root folders must remain.
So far I have been done with my weak knowledge of c# and and now I'm stuck for a long time.
DeleteFilesFromDirectory only deletes the first line of textBox1.



How to make DeleteFilesFromDirectory read and delete all lines from textBox1?










share|improve this question
























  • So the root folder is downloads,doc,etc ?

    – Marios Nikolaou
    Mar 23 at 11:10











  • If given path is F:/doc/scan, then need to be wiped everything under folder scan, but leave root folder scan empty

    – Uldis
    Mar 23 at 11:52














-1












-1








-1


1






Good day!



I'm trying to create a C # Forms app where user chooses directories with FolderDialog and paths are saved in list.txt file after read by textBox1.
In list.txt user can add and delete path.



code snippet:



private void Form1_Load(object sender, EventArgs e)

textBox1.Lines = System.IO.File.ReadAllLines(fileName);

string fileName = Environment.CurrentDirectory + @"/etc/list.txt";

private void LoadTextboxes()

string[] loadedLines = System.IO.File.ReadAllLines(Environment.CurrentDirectory + @"/etc/list.txt");

int index = 0;

int n = int.Parse(loadedLines[index]);
string[] lines = new string[n];
Array.Copy(loadedLines, index + 1, lines, 0, n);
textBox1.Lines = lines;

private void DeleteFilesFromDirectory(string directoryPath)

DirectoryInfo d = new DirectoryInfo(directoryPath);

foreach (FileInfo fi in d.GetFiles())

fi.Delete();


foreach (DirectoryInfo di in d.GetDirectories())

DeleteFilesFromDirectory(di.FullName);

di.Delete();



private void button1_Del(object sender, EventArgs e)

DeleteFilesFromDirectory(textBox1.Text);



list.txt format:



C:/downloads
F:/doc/scan
D:/etc


t is important to delete only the sub folders and files but root folders must remain.
So far I have been done with my weak knowledge of c# and and now I'm stuck for a long time.
DeleteFilesFromDirectory only deletes the first line of textBox1.



How to make DeleteFilesFromDirectory read and delete all lines from textBox1?










share|improve this question
















Good day!



I'm trying to create a C # Forms app where user chooses directories with FolderDialog and paths are saved in list.txt file after read by textBox1.
In list.txt user can add and delete path.



code snippet:



private void Form1_Load(object sender, EventArgs e)

textBox1.Lines = System.IO.File.ReadAllLines(fileName);

string fileName = Environment.CurrentDirectory + @"/etc/list.txt";

private void LoadTextboxes()

string[] loadedLines = System.IO.File.ReadAllLines(Environment.CurrentDirectory + @"/etc/list.txt");

int index = 0;

int n = int.Parse(loadedLines[index]);
string[] lines = new string[n];
Array.Copy(loadedLines, index + 1, lines, 0, n);
textBox1.Lines = lines;

private void DeleteFilesFromDirectory(string directoryPath)

DirectoryInfo d = new DirectoryInfo(directoryPath);

foreach (FileInfo fi in d.GetFiles())

fi.Delete();


foreach (DirectoryInfo di in d.GetDirectories())

DeleteFilesFromDirectory(di.FullName);

di.Delete();



private void button1_Del(object sender, EventArgs e)

DeleteFilesFromDirectory(textBox1.Text);



list.txt format:



C:/downloads
F:/doc/scan
D:/etc


t is important to delete only the sub folders and files but root folders must remain.
So far I have been done with my weak knowledge of c# and and now I'm stuck for a long time.
DeleteFilesFromDirectory only deletes the first line of textBox1.



How to make DeleteFilesFromDirectory read and delete all lines from textBox1?







c# visual-studio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 10:59







Uldis

















asked Mar 23 at 10:54









UldisUldis

11




11












  • So the root folder is downloads,doc,etc ?

    – Marios Nikolaou
    Mar 23 at 11:10











  • If given path is F:/doc/scan, then need to be wiped everything under folder scan, but leave root folder scan empty

    – Uldis
    Mar 23 at 11:52


















  • So the root folder is downloads,doc,etc ?

    – Marios Nikolaou
    Mar 23 at 11:10











  • If given path is F:/doc/scan, then need to be wiped everything under folder scan, but leave root folder scan empty

    – Uldis
    Mar 23 at 11:52

















So the root folder is downloads,doc,etc ?

– Marios Nikolaou
Mar 23 at 11:10





So the root folder is downloads,doc,etc ?

– Marios Nikolaou
Mar 23 at 11:10













If given path is F:/doc/scan, then need to be wiped everything under folder scan, but leave root folder scan empty

– Uldis
Mar 23 at 11:52






If given path is F:/doc/scan, then need to be wiped everything under folder scan, but leave root folder scan empty

– Uldis
Mar 23 at 11:52













1 Answer
1






active

oldest

votes


















0














Check this I tested it.



 //put all paths in array reading line by line
string[] paths = System.IO.File.ReadAllLines(@"path-tolist.txt");

//get line by line paths
foreach (string path in paths)

if (Directory.Exists(path))

//deletes all files and parent
//recursive:true, deletes subfolders and files
Directory.Delete(path, true);
//create parent folder
Directory.CreateDirectory(path);


//end outer for





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312958%2fc-sharp-forms-read-textbox1-all-lines-and-delete-given-paths%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Check this I tested it.



     //put all paths in array reading line by line
    string[] paths = System.IO.File.ReadAllLines(@"path-tolist.txt");

    //get line by line paths
    foreach (string path in paths)

    if (Directory.Exists(path))

    //deletes all files and parent
    //recursive:true, deletes subfolders and files
    Directory.Delete(path, true);
    //create parent folder
    Directory.CreateDirectory(path);


    //end outer for





    share|improve this answer



























      0














      Check this I tested it.



       //put all paths in array reading line by line
      string[] paths = System.IO.File.ReadAllLines(@"path-tolist.txt");

      //get line by line paths
      foreach (string path in paths)

      if (Directory.Exists(path))

      //deletes all files and parent
      //recursive:true, deletes subfolders and files
      Directory.Delete(path, true);
      //create parent folder
      Directory.CreateDirectory(path);


      //end outer for





      share|improve this answer

























        0












        0








        0







        Check this I tested it.



         //put all paths in array reading line by line
        string[] paths = System.IO.File.ReadAllLines(@"path-tolist.txt");

        //get line by line paths
        foreach (string path in paths)

        if (Directory.Exists(path))

        //deletes all files and parent
        //recursive:true, deletes subfolders and files
        Directory.Delete(path, true);
        //create parent folder
        Directory.CreateDirectory(path);


        //end outer for





        share|improve this answer













        Check this I tested it.



         //put all paths in array reading line by line
        string[] paths = System.IO.File.ReadAllLines(@"path-tolist.txt");

        //get line by line paths
        foreach (string path in paths)

        if (Directory.Exists(path))

        //deletes all files and parent
        //recursive:true, deletes subfolders and files
        Directory.Delete(path, true);
        //create parent folder
        Directory.CreateDirectory(path);


        //end outer for






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 23 at 12:55









        Marios NikolaouMarios Nikolaou

        424416




        424416





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55312958%2fc-sharp-forms-read-textbox1-all-lines-and-delete-given-paths%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현