Dodger42
asked on
In file text substitution
I am a novice programmer, but trying to learn how to solve a requirement. I have a tool whose config file contains a staticly map to a file. Unfortunately that file changes regularly (including filename, and possibly extension) and I need the tool to reference the new file. I want to create some code to search a directory for the most recently created file, which then takes that filename, and substitutes the static entry in the tool's configuration file.
I have been searching a little and have absolutely no idea where to begin. I only have tools to work with Visual Studio.Net.
Does anybody have any suggestions?
Thanks!!!!
I have been searching a little and have absolutely no idea where to begin. I only have tools to work with Visual Studio.Net.
Does anybody have any suggestions?
Thanks!!!!
1. Is the file always in the same directory?
2. If the name and/or extension of the file changes, what would a program look for to identify it? Might "old" versions of the file still exist?
3. If presented with more than one possibility, would program choose the one with latest altered date/time?
The code to do this is fairly simple if the above answers are available.
2. If the name and/or extension of the file changes, what would a program look for to identify it? Might "old" versions of the file still exist?
3. If presented with more than one possibility, would program choose the one with latest altered date/time?
The code to do this is fairly simple if the above answers are available.
Take a look at this , you can search based on different file criteria etc using this :
http://vbnet.mvps.org/index.html?code/fileapi/recursive.htm
http://vbnet.mvps.org/index.html?code/fileapi/recursive.htm
This is very easy to do in DotNet. Here's a c# example:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
public static void Main()
{
System.IO.FileSystemWatche r f=new System.IO.FileSystemWatche r("c:\\tes t");
f.NotifyFilter=NotifyFilte rs.FileNam e | NotifyFilters.Attributes | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;
f.Created+=new System.IO.FileSystemEventH andler(Mes sage);
f.Deleted+=new System.IO.FileSystemEventH andler(Mes sage);
f.EnableRaisingEvents=true ;
Application.Run(new Form1());
}
public static void Message(object o, System.IO.FileSystemEventA rgs e)
{
MessageBox.Show(e.Name.ToS tring() + " " + e.ChangeType.ToString());
}
// c:\test is not being monitored for new files/deleted files, among other things. Play with it. Good luck!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
public static void Main()
{
System.IO.FileSystemWatche
f.NotifyFilter=NotifyFilte
f.Created+=new System.IO.FileSystemEventH
f.Deleted+=new System.IO.FileSystemEventH
f.EnableRaisingEvents=true
Application.Run(new Form1());
}
public static void Message(object o, System.IO.FileSystemEventA
{
MessageBox.Show(e.Name.ToS
}
// c:\test is not being monitored for new files/deleted files, among other things. Play with it. Good luck!
ASKER
1. Is the file always in the same directory?
Yes!
2. If the name and/or extension of the file changes, what would a program look for to identify it? Might "old" versions of the file still exist?
Filename will change incrementally, their are two different extension possibilities. Need to filter based on those two possibilities.
3. If presented with more than one possibility, would program choose the one with latest altered date/time?
The latest file with the permitted extension would always be selected.
Thanks Heaps!
Yes!
2. If the name and/or extension of the file changes, what would a program look for to identify it? Might "old" versions of the file still exist?
Filename will change incrementally, their are two different extension possibilities. Need to filter based on those two possibilities.
3. If presented with more than one possibility, would program choose the one with latest altered date/time?
The latest file with the permitted extension would always be selected.
Thanks Heaps!
ASKER
Sorry, my C is average, but will give that a shot GGalbo! I am more familiar with vb.net ;)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
then the things are easy. u just open ur config file and replace it ...
Regards
Rajesh