USER command questions
John Esak
john at valar.com
Thu Sep 10 19:24:23 PDT 2009
As most know... my eyes play tricks on me... mostly in not working at all,
period... but I added the cnt(4,.0) variable to the wrong example below. It
obviously should be where the second declare of nu_files(4,.0) is. I went
bakc up and declared the cnt on the wrong example stub, sorry. I'm hoping
you can see that it belonged where I doubled num_files by mistake.
Good luck
_____
From: filepro-list-bounces+john=valar.com at lists.celestial.com
[mailto:filepro-list-bounces+john=valar.com at lists.celestial.com] On Behalf
Of John Esak
Sent: Thursday, September 10, 2009 10:19 PM
To: 'Tyler'; filepro-list at lists.celestial.com
Subject: RE: USER command questions
You are using the wrong filePro tool entirely.
I believe this could be written in about 5 lines of code if you were to do
it with the right processing. The user command is not in any stretch the
right function to use to do what you want to accomplish.
You sound frustrated at filePro for not being able to do something simple.
You haven't taken the time to find out how this should be done. I suppose
it is admirable that you at least tried something you thought might work.
However, when it didn't work, your bashing about on filePro is
disheartening.
When you want to open a directory (folder) and do something to each of the
files you find therein, use the "opendir() function.
It has some special masks to show you only the specified filePro format
types of screens outputs, etc. But, its real value is just specifying some
wildcard to retrieve only the exact files you want. You could specify "*"
and get every file in a directory (in which case you will also get the . and
.. entrires, so you have to be aware of this and skip over them with a test.
But essentially, to use opendir() you do it like this:
then: declare num_files(4,.0), cnt(4,.0); cnt="1"
then: num_files=opendir("*","/tmp/path/to/dir")
After the the line with the opendir() is exectured, the system maintained
arrays @dirlist, @dirlist_filename and @dirlist_name and @dirlist_ext are
filled immediately with all the filenames (and dirnames) found in that
wildcard search of the specified folder. In this case "*" (it could be
"*.txt" or "*.csv" and so on, then you would only get that wildcarded group
of files thrown into the @dirlist arrays.) It is important to note that the
opendir() command works like all the other file I?O commands in that it
returns a value to the variable on the left side of the operation. So, not
only are these arrays filled with the file and directory names found by the
wild card filter, but the total number of them is stored into the variable
you put in the opendir() command. In my example num_files. (Check the manual
for what @dirlist_filename/name/ext each actually hold. It is clearly laid
out there.)
This is extremely useful because you can start a counter like I'm showing
above, and point to each file found in the directory until you reach the
total number of files found by the search... then you end the operation and
move on. In other words when cnt goes one higher than num_files, you are
done.
So, you will be saying something like the following. It will be somewhat
stylized, I haven't looked closely at your code, and don't have time to code
exadctly what you need... but you can modify the code I"ll write now in
about 3 minutes to do just what you need done. Here I go, I'm timing
myself....
<GET_TIME>
then: declare num_files(4,.0), num_files(4,.0); cnt="1"
then: num_files=opendir("*","/some/path/to/a/folder")
loop if: cnt gt num_files
then: num_files=closedir(); return (or go somewher else)
if: @dirlist_filename[..] eq "." or @dirlist_filename [cnt] eq
".."
then: cnt=cnt + "1"; goto loop
if: @dirlist_filename[cnt] eq "something you want" to move"
then: declare SysCmd; SysCmd="mv" < @dirlist_filename[cnt]
the_other_place_and_name { ""
then: system SysCmd
then: cnt=cnt + "1"; goto loop
</GET_TIME> Just about 1 minute 30 seconds.
So, you see, it is not so difficult to do a simple job in filePro if you use
the right tool.
Good luck,
John Esak
P.S. Tyler, please note the num_files=closedir() it is very important to
close the opening of the directory when you're done. You may want to open
another folder and you would not be able to do it unless you execute the
closedir(). Do it without arguments and into any variable... why not the
one that was used to hold the total number of found files.
_____
From: filepro-list-bounces+john=valar.com at lists.celestial.com
[mailto:filepro-list-bounces+john=valar.com at lists.celestial.com] On Behalf
Of Tyler
Sent: Thursday, September 10, 2009 8:33 PM
To: filepro-list at lists.celestial.com
Subject: USER command questions
Has anyone managed to get his to work on SCO Openserver with the mv or cp
commands? I can get ls to work, but no matter what I try I get the command
usage output to std err. These are such basic commands I can't believe they
wouldn't work for USER as it is described in the manual.
All I really want is to list the csv files in a directory, process them,
then move them to another directory. This extremely basic file manipulation
to be ridiculous difficult to do in filePro!
Here is what I have:
::DECLARE filepath(128,*); filepath="/public/mailerListsSent/Prospects/":
::DECLARE filename(32,*):
::debug on:
::USER dirlist = ls:
::USER move = mv:
::dirlist=filepath{"/*.csv"; filename=dirlist:
loop01s:filename eq "":goto loop01e:
::show filename:
::'msgbox filepath{filename<filepath{"imported/"{filename:
::'goto loop01n:
::move = "-f":
::move = filepath{filename:
::move = filepath{"imported/"{filename:
::i=move:
::end:
loop01n::filename=dirlist; goto loop01s:
loop01e:::
Can anyone tell me how to use cp or mv with the USER command? Or is it just
garbage and I should go back to SYSTEM?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.celestial.com/pipermail/filepro-list/attachments/20090910/f8aa6e80/attachment-0001.html
More information about the Filepro-list
mailing list