Link to home
Start Free TrialLog in
Avatar of Abhishek Modak
Abhishek ModakFlag for India

asked on

Recursively finding text files within a specified folder and appending its contents

I want to make a Windows application form that should select a particular folder and then append or overwrite all the text files that are discovered after recursively searching for text files by "hello world" text. All the discovered text files must then contain "hello world" as their content.how to do it in c#?
Avatar of Darrell Porter
Darrell Porter
Flag of United States of America image

Do you mean files whose extensions are '.TXT'?
First, I would enumerate the folder and all child objects which are not links or junctions.
Filter this collection by items of whose suffix matches the suffix you're looking for.
Check to see if you have permissions to write to the filtered file objects in the collection.
Use the

public static StreamWriter AppendText(
	string path
)

Open in new window


where path is the path to the file and append the string in question.
Avatar of Abhishek Modak

ASKER

Yup,I mean the the files whose extension is .txt
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.