Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to read a content in notepad and search the content file in one folder and move the file to other folder ? Plz help me to develope in windows form application
Posted
Updated 1-Jul-14 0:26am
v5
Comments
Prasad Avunoori 1-Jul-14 6:32am    
How the data look like in your first txt file?
johannesnestler 1-Jul-14 8:00am    
Solutions excepted but still no clue?

Please see the sample for your reference.

C#
//search Content
            string sSearchContent = "Search Content";
            //Directory Path where all notepad file exist
            string sSourceFilesDirectory = "Directory Path";
            //Path where file moved if content matched in the file
            string sMoveFileDirectoryPath = "";
            List<string> lstContentMatchedFile = new List<string>();
            //Get all notepad file from directory
            string [] arrFiles = Directory.GetFiles(sSourceFilesDirectory, "*.txt");
            string sFileContent="";
            foreach (string sFile in arrFiles)
            {
                sFileContent = File.ReadAllText(sFile);
                if (sFileContent.Contains(sSearchContent))
                {
                    lstContentMatchedFile.Add(sFile);
                }
            }

            //Code to move file
            foreach (string sFile in lstContentMatchedFile)
            {
                File.Move(sFile, Path.Combine(sMoveFileDirectoryPath, Path.GetFileName(sFile)));
            }
 
Share this answer
 
Comments
Member 10916342 1-Jul-14 7:00am    
PLz explain the program as i am from non cse background.thanks in advance...!!
1. Read the file names in the text files, use File.ReadAllLines[^].
2. Iterate through the file names, and use File.Move[^] to move the file.
 
Share this answer
 
Comments
Member 10916342 1-Jul-14 7:24am    
where i have to give the notepad name and location ?Thanks in advance...!
Member 10916342 1-Jul-14 7:28am    
Plz someone help me yar ?
Member 10916342 3-Jul-14 6:10am    
please explain with an example......
[no name] 3-Jul-14 6:18am    
I've pointed you towards the right solution and there are plenty of examples available on the net. It's upto you to put the efforts and come up with the solution.
Member 10916342 3-Jul-14 6:26am    
plz shameel i don't get an example for this program.can u plz help me with an example.

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