?
Solved

In file text substitution

Posted on 2005-03-25
7
Medium Priority
?
267 Views
Last Modified: 2013-11-18
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!!!!
0
Comment
Question by:Dodger42
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 3

Expert Comment

by:r_a_j_e_s_h
ID: 13634980
u can write a simple c program to find the list of files in the directory.. u can also get the last modified time for that file. u have to get the latest modified file name first.. u have to use "findfirst" & "findnext" command.

then the things are easy. u just open ur config file and replace it ...


Regards
Rajesh
0
 
LVL 22

Expert Comment

by:JesterToo
ID: 13635285
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.
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13637046
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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:ggalbo
ID: 13638213
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.FileSystemWatcher f=new System.IO.FileSystemWatcher("c:\\test");
                  
                  f.NotifyFilter=NotifyFilters.FileName | NotifyFilters.Attributes | NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Security | NotifyFilters.Size;


                  f.Created+=new System.IO.FileSystemEventHandler(Message);
                  f.Deleted+=new System.IO.FileSystemEventHandler(Message);
                  
                  f.EnableRaisingEvents=true;
                  
                  Application.Run(new Form1());
                  
            }

            

            public static void Message(object o, System.IO.FileSystemEventArgs e)
            {
                  MessageBox.Show(e.Name.ToString() + " " + e.ChangeType.ToString());
            }


// c:\test is not being monitored for new files/deleted files, among other things.  Play with it.  Good luck!
0
 

Author Comment

by:Dodger42
ID: 13638690
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!
0
 

Author Comment

by:Dodger42
ID: 13638692
Sorry, my C is average, but will give that a shot GGalbo! I am more familiar with vb.net ;)

0
 
LVL 1

Accepted Solution

by:
ggalbo earned 500 total points
ID: 13639629
The syntax for the c# version I gave you and VB.net version is very similar.  Really, the biggest difference is how to hook into the event (keep in mind that the events and delegates are already written, we just have to write the handler.  In the above example, I called mine Message).  
In c# I did this by f.Created+=new System.IO.FileSystemEventHandler(Message);

I believe in VB.net you do this by using the addressof operator: AddHandler f.Created AddressOf Message

Everything else is a question of deleting semicolons and brackets, and the "Using" at the top of the program should be changed to "Imports"
Of course, all of this is moot, since this is all in .NET....you can simply use a c# class from your VB.net app...but since you want to play with it, I thought I'd give some hints on how to convert it. :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A short article about problems I had with the new location API and permissions in Marshmallow
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question