Google Answers Logo
View Question
 
Q: Read from specific folder, any file that might be in that folder GA ( Answered 5 out of 5 stars,   0 Comments )
Question  
Subject: Read from specific folder, any file that might be in that folder GA
Category: Computers > Programming
Asked by: amy123456-ga
List Price: $70.00
Posted: 19 Feb 2004 12:27 PST
Expires: 20 Mar 2004 12:27 PST
Question ID: 308505
Hi. You created the following code to read from a specific file. Can we make it 
read from a specific folder what ever file is in the folder. ( The
files are all going to remain the same, just the file name will change
ever time rpm sends the file)

TxtXtrct.ListItems("c:\\lightsr\\Crystal_Reports_-_Order_Entry_Summary_Report.doc");
			return;
		}


		/*public static void Main(string[] args)
		{
		if (args.Length == 0)
		{
		Console.WriteLine("order.rtf");
		}
		else
		{
		TxtXtrct.ListItems(args[0]);
		}
		return;
	}*/

		/// <summary>
		/// Method for extracting text items from file
		/// </summary>
		/// <param name="filename">root/path/filename.ext</param>
		static void ListItems(string filename)
		{
			if (!File.Exists("c:\\lightsr\\Crystal_Reports_-_Order_Entry_Summary_Report.doc"))
			{
				Console.WriteLine(
					"Error: Specified file {0} does not exist.",
					filename);

				return;
			}

			StreamReader sr =
File.OpenText("c:\\lightsr\\Crystal_Reports_-_Order_Entry_Summary_Report.doc");

Request for Question Clarification by mathtalk-ga on 19 Feb 2004 19:59 PST
Hi, Amy:

Will the filename _extension_ (generally a three letter part, after
the period in the filename) always be the same?  It looks like you've
used .doc in your example.

My thought is to write a routine that takes a "path" (folder name) as
its input, looks in the folder for files with the given extension,
changes the extension of one of them to .tmp (temporarily) while it
reads from the file, then closes it and changes the extension to .dne
(done).

This "three phase" process allows us to deal with a situation in which
more than one file may be present in the folder in a systematic way.

What do you think?

regards, mathtalk-ga

Clarification of Question by amy123456-ga on 20 Feb 2004 04:36 PST
Hi. the extension will all ways be .doc.  Would it be easier to just
delete the file after it is read, since we are already parsing out the
file and saving it to another location already.

PS. You are the expert, i trust your jugedment.

Thank you

Clarification of Question by amy123456-ga on 15 Mar 2004 17:10 PST
Hi MathTalk.  are you thinking of creating a user interface for
turning the lights out?

Clarification of Question by amy123456-ga on 15 Mar 2004 17:58 PST
Hi Again. How long do you think this piece should take?

Thank you

Request for Question Clarification by mathtalk-ga on 16 Mar 2004 06:46 PST
I'll certainly try to wrap these up late Thursday, so you can check
things over on Friday.  I'll be travelling next week, and my Internet
availability may be impaired!!

-- mathtalk-ga

Clarification of Question by amy123456-ga on 16 Mar 2004 07:37 PST
Thank you

Request for Question Clarification by mathtalk-ga on 17 Mar 2004 07:05 PST
Hi, Amy:

I anticipate that you will want to wrap into the "looping" issue
originally presented here (find any file(s) the might be in the
folder) the characteristics of files that might be inserted, not by
the "printer" but by the floor nurses who are acknowledging the
completion of a particular room/patient's outstanding orders.

Please sketch the data items that you will want to log when a nurse
indicates that the light for a room should be cleared.  Possibly this
includes the identity of the nurse, as well of course as the room
number.  The timestamp can be picked up from the creation date of the
file.  I was thinking of:

name of file :  keyed to room number (there should only be one at a time)
file content :  based on nurse's identity
timestamp    :  from file's creation date

I'm picturing a small WinForms application that a nurse "signs in" on
and picks a room number (or possibly more than one) as "clear".  This
application drops a file (or several) into the same folder where the
printer files are directed.  The Switchbox application would look
first for "lamp off" instructions from the nurses and second for "lamp
on" instructions from the printer (new doctor orders).  The rationale
for doing things in this order is that we don't want an older
fulfillment to mask a new order.

regards, mathtalk-ga

Clarification of Question by amy123456-ga on 17 Mar 2004 11:59 PST
Hi. MathTalk. 

All that is needed for the log is
1-User name
2-Timestamp
3-Room #

Thank you

Clarification of Question by amy123456-ga on 17 Mar 2004 12:08 PST
Hi MathTalk.

When the application looks in inside the folder called (SCM Orders)we
need it to take any file that is there that has the ext .doc   and
process it as an order. We can in the same manner take any file in the
same folder with an ext of  .txt as the instructions to turn off
lights.

If i understood you correctly i think we are on the same page.

Thank you

Request for Question Clarification by mathtalk-ga on 17 Mar 2004 18:11 PST
Hi, Amy:

Given my weakness for puns, I was thinking of an extension .prn.  But
with your good influence I can resist the temptation.

:grin:

-- mathtalk-ga

Clarification of Question by amy123456-ga on 18 Mar 2004 03:21 PST
Hi. The ext can be anything as long as the application can process it.

Thanks MathTalk

Clarification of Question by amy123456-ga on 19 Mar 2004 05:14 PST
Hi MathTalk. No Pressure!!!!!!! just checking to see if you might have 
something for me today. I would like to schedule for a demo on monday 
with the staff. If i can digest and set it all up today i think  it will
work nicely.

Thank you Very much

Request for Question Clarification by mathtalk-ga on 19 Mar 2004 08:19 PST
Hi, Amy:

Sorry, but I feel behind this week with work & a touch of illness.

I suggest setting up the demo for Tuesday.  I'll provide a "user
interface" program that I'll provide, i.e. one a nurse would use to
log an order fulfillment, but you'll probably need to polish it for a
presentation.

I'll see if I can whip up something on my lunch hour to get you started.

-- mathtalk-ga

Clarification of Question by amy123456-ga on 19 Mar 2004 09:13 PST
I am sorry you are not felling well. Eat some home made chicken soap.
That is fine. I will reschedule for tuesday. 

If you send me the interface  i will do all the polishing up.

Thank you very much
Answer  
Subject: Re: Read from specific folder, any file that might be in that folder GA
Answered By: mathtalk-ga on 20 Mar 2004 04:26 PST
Rated:5 out of 5 stars
 
Hi, Amy:

Well, here's a rough stab at the user interface; right now it just
pops up a dialog box, but we can put code inside the button1 Click
handler that writes the file in the proper directory.

Download from here:

http://68.15.21.151/uploads/researchers/OrderF.zip

and you'll see that it's a Windows app written in C#.  I thought about
doing it in Visual Basic, which would have been a tad easier, but I
was worried maybe you somehow only have the C# tools.  Anyway, in for
a penny, in for a pound...

Now I'll work on the mods to the file folder search loop.  I'll assume
the floor order fulfillment files will be called:

PRNnn.prn

and that the content of the file will be (presumably one line of)
information to log, similar to what we do for turning the light on
(except here we are turning light for room number nn off).

Note that if by chance the same light gets "turned off" twice before
it can be picked up, the first file would be overwritten by the second
and only one lamp off instruction logged, but I don't think this is
likely to occur except when the button is clicked twice (eg. by
accident) and no great loss there.

regards, mathtalk-ga

Request for Answer Clarification by amy123456-ga on 21 Mar 2004 11:37 PST
Hi MathTalk.  The new user interface app will send a file to the same
location(Folder) that the main application looks for new orders
wright? So their will be some modification to the code to reflect
actions needed for the file that came from the user interface to turn
the lights off.
Will you be able to have test for me today?   Thank you Mathtalk

Clarification of Answer by mathtalk-ga on 21 Mar 2004 17:00 PST
Yes, I will be able to get the test code today/tonight, so you can
tweak it tomorrow (Monday), in preparation for the demo on Tuesday...

regards, mathtalk-ga

Request for Answer Clarification by amy123456-ga on 22 Mar 2004 03:58 PST
I am a little nervous doing this in front of all the big chiefs, but I
know everything will go well.

Thank you Mathtalk

Clarification of Answer by mathtalk-ga on 22 Mar 2004 11:09 PST
Hi:

The revised code of searching the folder for both kinds of files (lamp
on, lamp off) is in the same link as before:

http://68.15.21.151/uploads/researchers/switchbox.zip

It looks in the c:\lightsr directory, based on that being a command
line argument.  You can set a command line argument with a Windows
"shortcut", for example, putting C:\lightsr behind the "target"
executable (but _not_ inside the parentheses that bracket the
executable name, if any.

I'll send some additional details, but it runs in a loop until it
finds a file in the same directory called "worldstop.the".  Files
called *.doc are parsed as before for patient room number info and the
lamp turned on accordingly.  Files called PRNxx.prn are parsed as
instructions to turn the lamp for room number xx off.

Let me know if there are some issues about running the 'switchbox' and
in the meantime I'll add the code to the Windows "order fulfillment"
app to write a file named PRNxx.prn to the same directory.

regards, mathtalk-ga

Request for Answer Clarification by amy123456-ga on 22 Mar 2004 12:05 PST
Thank you, I will let you know.

Request for Answer Clarification by amy123456-ga on 22 Mar 2004 18:07 PST
Hi. The order file that gets parsed out and sent to the log happened
on the previous version, but here i do not see where the log file gets
created and the
orders parse out to the log. Was it eliminated?

PS- Like you said it remains on a constant loop once started.

Thank you

Clarification of Answer by mathtalk-ga on 23 Mar 2004 04:43 PST
Hi, Amy:

The logfile is still getting the patients' order info as before, in
C:\txtxtrct.log, but I haven't added the counterpart info from order
fulfillment.  It's on my "to do" list.

I've put some code into the small Windows applet that writes the .prn
files (to the required directory, again passed as a commandline
argument).  But there's a glitch with the list box that selects the
room number.  If the user clicks into that box, then the room number
is selected and all works well.  However the intuitive thing is simply
to use the scroll arrows next to the list box, and by itself this
doesn't select the text entry.  I'm working on it...

Good luck with your presentation!

Best wishes, mathtalk-ga

Request for Answer Clarification by amy123456-ga on 23 Mar 2004 08:49 PST
Hi MathTalk. Can we just make the user interface showing all the room
#'s. that way they will have to choose the room # that they want.

PS- I can build the form with all the room # listed. If you can do the
code behide the form.

Let me know what you think.


Thank you

Request for Answer Clarification by amy123456-ga on 23 Mar 2004 09:13 PST
Hi MathTalk. When i run the new version at work, all the lights that
needed to go on did ( 6 lights), when i turn off world 1 on porpose to
show how it remembers the privious settings of the lights, Only one
light was turned on when the application ran after restart.

Thank you

Request for Answer Clarification by amy123456-ga on 23 Mar 2004 09:32 PST
This is the error on the console.

Warning: Specified map file worldmap.xml does not exist.
Warning: Initializing with blank map.

I removed the file to see if it would create another, but it did not, and 
it gave me the error above. 

When i look in the debug for the worldmap.xml the file does not exist.

Thank you MathTalk

Clarification of Answer by mathtalk-ga on 24 Mar 2004 07:21 PST
Hi, Amy:

First let me tell you what I think is going on with the worldmap.xml
file.  This is created when the program terminates normally.  To get
the program to terminate normally you should introduce a file named
"worldstop.the" into the same directory as the other files are going
(C:\lightsr).  Contents of worldstop.the are unimportant, and the file
will be removed when the application restarts.

If you terminate the program using the Debug menu or in some other
"abrupt" fashion (like closing the Console command window), then the
worldmap.xml file is not saved.  However the application does
initialize the "map" internally from scratch whenever the worldmap.xml
file cannot be found.

Now on the design of the user-interface, I think you are proposing an
array either of "radio buttons" or check boxes corresponding to the
various room numbers.  I agree that this would make the interface more
intuitive.

The main difference is whether you intend to allow only one room at a
time (radio button) or multiple rooms (check boxes) to be selected. 
I'd suggest going with the radio buttons.  The user should focus on
one room at a time, and IMHO allowing multiple rooms to be selected
invites more carelessness.  Also the application does not close (as
written now), so if a user wants to do a second or third room, there's
not much overhead involved.

You'll probably need to incorporate some sort of validation of user
IDs, if not of an actual login procedure at some point.

But let me know if you want radio buttons numbered 1 through 28, and
I'll take care of it.

regards, mathtalk-ga

Clarification of Answer by mathtalk-ga on 24 Mar 2004 07:25 PST
A simple way to interactively create the worldstop.the file when the
application is running is to open a Windows Explorer window on the
proper directory (C:\lightsr) and right click to create a New... Text
Document (or any kind of file), then rename the file (to
worldstop.the).

-- mathtalk-ga

Request for Answer Clarification by amy123456-ga on 24 Mar 2004 14:05 PST
Hi MathTalk. Radio buttons numbered 1 through 28 is ok with me.  Thank
you very much once again.

PS- When the project is all done and complete there will be a bonus. Thank you

Clarification of Answer by mathtalk-ga on 27 Mar 2004 07:56 PST
Hi, Amy:

By way of a progress report, I added the 28 radio buttons to a form
(with an "ID" text box and "DONE" button) and verified their
"exclusive check" settings.

I've written this revised "Order Fulfillment" project as part of the
textextract "solution", just to start putting all our pieces in one
place.  I can also create a small application that simple writes a
file named worldstop.the to the appropriate directory.

regards, mathtalk-ga

Request for Answer Clarification by amy123456-ga on 27 Mar 2004 22:05 PST
Hi MathTalk.  Will you be able to have something for me on sunday for testing.

i do appreciate your efforts

Thank you very much.

Clarification of Answer by mathtalk-ga on 28 Mar 2004 22:50 PST
Hi, Amy:

Okay, I've added two new "projects" to the textextract "solution" and
refreshed the switchbox.zip link accordingly (the netserialcomm
project/solution is unchanged from the past few weeks).

The first "new" project is just the Order Fulfillment Windows
application, now written to use 28 radio buttons for the various room
number options.  I've also added a timestamp to the contents of the
file that it writes out.  Two items that you will probably want to put
on the TO DO list:  something wrt verifying the user ID and modifying
the message box that "confirms" orders are cleared for a room to one
that actually allows the user a "cancel" option (in case they see that
the wrong room number is about to be cleared).

The second "new" project is a simple console application called
"stopworld" that creates a file name worldstop.the in the designated
directory.

Finally I've updated the textextract1 project itself to copy the
contents from the .prn files found to the log file (which is
effectively hardcoded at a top level of the program to
C:\txtxtrct.log, but it would be fairly straightforward to make this
another commandline option as well).

Please test and report any concerns or bugs.

regards, mathtalk-ga

Request for Answer Clarification by amy123456-ga on 29 Mar 2004 03:28 PST
Good morning MathTalk. Where did you put the zip file?

Thank you very much for your dedication to this project.

Clarification of Answer by mathtalk-ga on 29 Mar 2004 04:37 PST
Good morning, Amy:

The same location as before:

http://68.15.21.151/uploads/researchers/switchbox.zip

-- mathtalk-ga

Request for Answer Clarification by amy123456-ga on 29 Mar 2004 07:16 PST
Good morning MathTalk. I run the application and the lights went  on,
How does the form interect at this point so i can choose a room # to
turn the lights off.
The form does not seem to load and be insight.

Thank you

Clarification of Answer by mathtalk-ga on 29 Mar 2004 10:14 PST
Hi, Amy:

Perhaps you are running the textextract.exe from within the debugger. 
The Order Fulfillment application is a separate program, and probably
the most convenient way to run it would be to create a desktop
shortcut to launch it.

For a description of how to set the commandline options in a shortcut,
see my Clarification from March 22.  You can create a desktop shortcut
to the Order Fulfillment application by right-clicking on an empty
place on the desktop and selecting New... Shortcut from the menu.  A
Wizard will guide you through finding the Target executable, but you
then need to edit the Properties of the shortcut (again from a
right-click menu on the newly created desktop shortcut).  The
commandline options go in the same text box as the path and filename
of the executable, but at the end and _following_ any quotation marks
around the path and filename of the executable.  (Everything inside
the quotation marks gets treated as a single token by the file system,
and you'll likely get a file not found message if you put things
inside them.)

While you're at it, go ahead and create a similar shortcut for the
stopworld console application (including the commandline option
C:\lightsr).  This will allow you to stop the textextract program in
the correct manner (preserving the worldmap settings out to an XML
file).

regards, mathtalk-ga

Clarification of Answer by mathtalk-ga on 29 Mar 2004 10:36 PST
All three programs (textextract, Order Fulfillment, and stopworld)
could/should be run from shortcuts in production, and all three take a
single commandline option consisting of the directory in which the
"doc" files are going to show up (C:\lightsr if I've understood your
setup correctly).

Running the programs from within the Debugger/Visual Studio .Net is
great for diagnosing bugs and making quick fixes, but with shortcuts
you can leave the Order Fulfillment icon prominently displayed on the
Desktop for "end-users" to launch.  (The shortcuts for the other two
programs you will probably want to put in less obvious locations,
perhaps on a menu.)

-- mathtalk-ga

Request for Answer Clarification by amy123456-ga on 29 Mar 2004 13:31 PST
Hi MathTalk. I Am Sorry but you lost me, I apologize.
Could you please dummy proff the details.

I am very sorry and THANK YOU FOR YOUR help as always.

Clarification of Answer by mathtalk-ga on 29 Mar 2004 14:20 PST
Hi, Amy:

Okay, no problem.  To get prepared, take a look at some of the icons
on your desktop. If you right-click on one (put the mouse cursor there
and hit the right-side button on the mouse), a menu comes up and
probably the last item on the menu is Properties.  Click there and a
dialog with two or more tabs comes up, one of which says Shortcut.

Looking at the Shortcut tab of the Properties dialog, you should see a
text box that is called Target, kind of in the upper middle.

Have a look at several of these icons or "desktop shortcuts" as I've
been calling them, to get a feel for the connection between what the
icons do when you "open" or double-click them and the names of the
programs shown as Targets in the Properties.

We will then talk about creating your own icons or shortcuts.

regards, mathtalk-ga

Request for Answer Clarification by amy123456-ga on 29 Mar 2004 14:46 PST
Hi Mathtalk. Sorry, you lost me right after creating the short cut.  I know
how to creat a short cut. What i did not understand was going to the
properties and making all those changes to the short cut.

Thank you

Clarification of Answer by mathtalk-ga on 29 Mar 2004 16:09 PST
Hi, Amy:

Well, after the shortcut is created the only change required is very simple.

Let's say you have made a shortcut to myprog.exe in C:\Visual Studio
Projects, just to keep the details brief.  In this case the Target
shown in the shortcut Properties will look like this:

"C:\Visual Studio Projects\myprog.exe"

The reason for the quotation marks around the program name is to force
the command interpreter to recognize that this is a single token,
despite the embedded spaces in the directory name.  Otherwise it would
be looking for an executable file called C:\Visual, and trying to pass
the remaining tokens on the commandline as arguments to that program.

What I need you to do is to add the commandline option to the end of
the Target, _following_ the quotation marks and not inside them. 
Thus:

"C:\Visual Studio Projects\myprog.exe"  C:\lightsr

would pass one argument to the specified program.  If the argument
itself needs to have embedded spaces, it can be enclosed in a new set
of quotation marks.

So create a shortcut to the stopworld.exe program (for example), then
go into the shortcut Properties and edit the Target field to add
C:\lightsr (or other name of whatever folder into which you intend to
put the application files) as a trailing token.  Running the program
(by double clicking the shortcut) will simply create a file (called
worldstop.the) in whatever folder is designated.  This program could
be started from a commandline in a DOS box, but the desktop icon is a
great convenience.

Same thing applies to creating a shortcut for the Order Fulfillment
application.  Despite the fact that one is a "console" application and
one a "windows" application, there's a great deal of common "plumbing"
as far as the .Net programming model goes.

regards, mathtalk-ga

Clarification of Answer by mathtalk-ga on 29 Mar 2004 16:18 PST
Just to be clear, right click on any desktop shortcut (especially one
you've created) and you'll see a menu.  Properties should be the last
(bottom) item on that "right click" menu. (You can also use keyboard
strokes to get there, but the mouse is much easier to use unless
there's a mouse driver or mouse hardware problem.)

-- mathtalk-ga

Request for Answer Clarification by amy123456-ga on 29 Mar 2004 17:37 PST
Hi.  I an zip the file to  C:\project lights.

would the location of the exe be @

C:\project lights\textextract\orderfulfillment\bin\debug\OrderFulfillment.exe

Thank you

Request for Answer Clarification by amy123456-ga on 29 Mar 2004 17:52 PST
Hi Mathtalk. I got it to work.

Sorry for being a pain

Thank you.

Clarification of Answer by mathtalk-ga on 30 Mar 2004 02:05 PST
Okay, that's nice to hear, Amy!  I'm staying tuned...

-- mathtalk-ga

Request for Answer Clarification by amy123456-ga on 30 Mar 2004 03:41 PST
Hi mathTalk. The Id on the orderfulfillment- Novell has and
application that we use at work to verify user and PW- But it is for
VB. Do you think Novell might have one for C#?

I am going to do a full run at work in the morning, i will let you know.

Thank you very much again

Clarification of Answer by mathtalk-ga on 30 Mar 2004 04:04 PST
Hi, Amy:

The term for this Novell function is probably an "authentication API"
(where API means "application program interface").  If such an API can
be called from Visual Basic, we can almost certainly call it from C#
also (though it might be a little more difficult than do this from
VB6, and it would certainly be a good idea to find out what Novell has
done specifically for .Net applications).

regards, mathtalk-ga

Request for Answer Clarification by amy123456-ga on 30 Mar 2004 07:24 PST
Hi MathTalk. I ran the appilcation, but this time i sent a file
without the order session as the header to see what would happen. It
when on a continuous loop non stop.  Error: Order session header was
not found.

Clarification of Answer by mathtalk-ga on 30 Mar 2004 07:58 PST
Hi, Amy:

In such a case the worldstop.the file should still take precedence in
terms of stopping the application.  But I think the "looping" problem
is probably that the file is not being deleted in this case, so the
next time around the same file is located and produces the same error
message.

Maybe what we should do in such a case (a .doc file which we are
unable to parse) is to rename the file to *.err.  Then it will not be
found the next time through the loop but there would be record of it
occuring.  Of course if the filenames are not distinct, then there's a
chance that two names will coincide and we'll be unable to keep both.

How does that sound (keeping an .err file around in the directory as a
clue that a parsing error occurred)?

regards, mathtalk-ga

Request for Answer Clarification by amy123456-ga on 30 Mar 2004 08:50 PST
Sounds great.

Thank you

Clarification of Answer by mathtalk-ga on 31 Mar 2004 20:28 PST
Hi, Amy:

The switchbox.zip file, downloadable from the same link as before, has
been updated with new code that renames a .doc file that lacks the
"Order Session" header to be a .err file.  The file will remain in the
directory but will be ignored in further processing.

Try it and see if it does what you want!

regards, mathtalk-ga

Request for Answer Clarification by amy123456-ga on 01 Apr 2004 13:02 PST
Work really well. thank you

Clarification of Answer by mathtalk-ga on 01 Apr 2004 14:34 PST
My pleasure!  It's nice when the change requests find a natural place
in the existing code structure.

-- mathtalk-ga
amy123456-ga rated this answer:5 out of 5 stars
Execellet work as always.

Comments  
There are no comments at this time.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy