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;
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
add a comment |
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
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
add a comment |
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
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
c# visual-studio
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Mar 23 at 12:55
Marios NikolaouMarios Nikolaou
424416
424416
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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