Directory access from filePro
John Esak
john at valar.com
Mon May 16 16:05:17 PDT 2005
> I thought I remembered someone putting up a routine that would do what
> I'm looking for, but I couldn't find it in the list archives.
>
> I've got a routine that imports data from text files which are
> downloaded to us. As it is, it requires the user to know the file name
> of the file he wishes to upload. Instead, I would like to be able to
> present a list of files to the user in a listbox (or something similar),
> from which the user could select the text file to import.
I wrote this the other day for someone in the FP Room. I do not know who he
was. He just dropped in a couple times... Lou something I think. Anwyay.
Substitute whatever you want to do with the files in the Do_It subroutine
and you have a nifty way to process all and any files in a directory. The
colon separated (cut and paste) version follows this example.
If: 'List particular files in a directory and process them until
done.
1 Then: 'Run this with a blank screen "blank" and the following command
If: 'dclerk filename -sblank -z this_prc -a -h "Pick file to
process."
2 Then:
3 Then: end
@once If: '@once
4 Then:
If: 'Setup dirs /tmp/somedir, /tmp/somedir/in,
/tmp/somedir/archive
5 Then: 'to test, make some junk files called bill.csv, fred.csv in
"in"
If: 'I'll leave you to ensure that file/dir permissions are good
6 Then: 'for filePro. YMMV Be careful about this. It's always a hassle.
7 Then: DirShare="/tmp/somedir"; DirIn="in"; DirArc="archive"
8 Then: DirName=DirShare { "/" { DirIn
9 Then: '
loop_S If: 'loop_S 'show the files available
10 Then:
11 Then: showctr("19") "Press \KY to Exit Without Choosing A File"
If: 'show only the .csv files in this directory
12 Then: Number_Of_Files=opendir("*.csv",DirName)
If: Number_Of_Files eq "0"
13 Then: Number_of_Files=closedir(); mesgbox "No More Files."; EXIT
14 Then: Choice=listbox(@dirlist_filename)
If: @sk eq "BRKY"
15 Then: Number_Of_Files=closedir(); EXIT
16 Then: InFile=@dirlist_filename[choice]
17 Then: cls("19","1")
18 Then: mesgbox("17","-1") "Move the file \r" { InFile {
"\r?","(y/n)==>
","YN"
If: @sk eq "BRKY"
19 Then: Number_Of_Files=closedir(); EXIT
If: @bk ne "Y"
20 Then: goto loop_S
21 Then: gosub Do_It
22 Then: Number_Of_Files=closedir()
23 Then: goto loop_S
Do_It If: 'Do_It 'do whatever with the file, this just moves it...
24 Then:
25 Then: Arcfile=DirShare { "/" { DirArc { "/" { "arc_" { InFile
26 Then: SysCmd="mv" < InFile < Arcfile
27 Then: System SysCmd
28 Then: return
declist If: 'declist
29 Then:
30 Then: declare DirShare, DirIn, DirArc, InFile, ArcFile, DirName
31 Then: declare Choice(2,.0), Number_Of_Files(2,.0)
32 Then: declare SysCmd
(you will have to join these lines correctly after you cut/pste them.)
:'List particular files in a directory and process them until done.:'Run
this wi
th a blank screen "blank" and the following command:
:'dclerk filename -sblank -z this_prc -a -h "Pick file to process."::
::end:
@once:'@once::
:'Setup dirs /tmp/somedir, /tmp/somedir/in, /tmp/somedir/archive:'to test,
make
some junk files called bill.csv, fred.csv in "in":
:'I'll leave you to ensure that file/dir permissions are good:'for filePro.
YMMV
Be careful about this. It's always a hassle.:
::DirShare="/tmp/somedir"; DirIn="in"; DirArc="archive":
::DirName=DirShare { "/" { DirIn:
::':
loop_S:'loop_S 'show the files available::
::showctr("19") "Press \KY to Exit Without Choosing A File":
: 'show only the .csv files in this
directory:Number_Of_Files=opendir("*.cs
v",DirName):
:Number_Of_Files eq "0":Number_of_Files=closedir(); mesgbox "No More
Files.";
EXIT:
::Choice=listbox(@dirlist_filename):
:@sk eq "BRKY":Number_Of_Files=closedir(); EXIT:
::InFile=@dirlist_filename[choice]:
::cls("19","1"):
::mesgbox("17","-1") "Move the file \r" { InFile { "\r?","(y/n)==> ","YN":
:@sk eq "BRKY":Number_Of_Files=closedir(); EXIT:
:@bk ne "Y":goto loop_S:
::gosub Do_It:
::Number_Of_Files=closedir():
::goto loop_S:
Do_It:'Do_It 'do whatever with the file, this just moves it...::
::Arcfile=DirShare { "/" { DirArc { "/" { "arc_" { InFile:
::SysCmd="mv" < InFile < Arcfile:
::System SysCmd:
::return:
declist:'declist::
::declare DirShare, DirIn, DirArc, InFile, ArcFile, DirName:
::declare Choice(2,.0), Number_Of_Files(2,.0):
::declare SysCmd:
More information about the Filepro-list
mailing list