Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to create an application on which first i have add one string like "Try Try But Don't Cry" i want to add this string to some files on my pc and then I want to delete "But" i want to check the files for that certain word weather that files contains that word or not if the files contains that word delete that word from files
Posted
Comments
CHill60 6-Apr-15 12:34pm    
So what have you tried so far?
Member 11057488 6-Apr-15 12:37pm    
i want to insert one string on ny file which is on my desktop.
then i have to detect all files that any specific word should be on that file text then delete that specific word from the string which is on that file
CHill60 6-Apr-15 12:39pm    
I didn't ask you what you wanted to do. I asked you what have you tried so far
Member 11057488 6-Apr-15 12:46pm    
I use this code

Directory.CreateDirectory("D:\\ABC");
Directory.CreateDirectory("c:\\avi");
FileStream fs = new FileStream("c:\\avi\\a1.bat", FileMode.OpenOrCreate, FileAccess.ReadWrite);
StreamWriter sw = new StreamWriter(fs);
sw.Write ("Try Try But Don't Cry");
sw.Close();
fs.Close();

By using following code i m able to add string in the above file but i dont konw how to detect files for "But" word means which files contains this text.And delete that Word from file but dont know how
jk0391 6-Apr-15 13:29pm    
sw.Write("Try Try But Don't Cry".Replace("But", ""));

Try that line, it removes But, or modify to your liking...

You can also store that string in a string variable and make the following procedure: if (variable.Contains("But")) {}

1 solution

So you simulating a virus and a virus scanner? You couldn't say that in your original post?

Your simulation is quite naive. Viruses don't infect data files. They infect executable files.

With binary files, you cannot use a StreamReader/Writer as it tries to interpret everything as text. You have to use the FileStream and its methods to read/write the file, but now you're not looking for a text string but a stream of bytes that makes up your virus signature.
 
Share this answer
 
Comments
Member 11057488 7-Apr-15 13:03pm    
actually i dont know how to explain what actually i m so m suffering from this problem sorry for trouble

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900