[Search for users]
[Overall Top Noters]
[List of all Conferences]
[Download this site]
Title: | -={ H A C K E R S }=- |
Notice: | Write locked - see NOTED::HACKERS |
Moderator: | DIEHRD::MORRIS |
|
Created: | Thu Feb 20 1986 |
Last Modified: | Mon Aug 03 1992 |
Last Successful Update: | Fri Jun 06 1997 |
Number of topics: | 680 |
Total number of notes: | 5456 |
473.0. "RE-FORMATTED DIRECTORY OUTPUT" by AZUR::OPERTO (Bonjour chez vous) Thu May 14 1987 12:05
Hi,
What do I need to do ?
1. Get a re-formatted directory listing on a choosen directory giving
the possibility to exclude some files (just as DIRECTORY/EXCLUDE does).
2. Do it fast.
Here's the work-around we've found, but it's pretty slow.
1. Use the DCL DIRECTORY command.
2. Process the informations obtained.
Is there a way to do this in one pass ?
Bye,
Michel.
$! The file-names, and their uses :
$!
$! Name Use
$!
$! 'tmpfil'a.tmp Raw directory listing
$! 'tmpfil'b.tmp Processed listing
$!
$ parsed_file_spec := 'p1 ! directory tree to scan
$ excluding_file := 'p2 ! files to exclude from the listing
$ tmpfil := dummy ! name of the created files
$!
$!
$ Directory-
/Nohead/Notrail/Date=All/Owner/Size/File_Id-
/Out='tmpfil'a.tmp-
/exclude='excluding_file-
'Parsed_File_Spec'
$Check_Exist:
$ Open/Read/Error=No_File Infile 'tmpfil'a.tmp
$!
$ Count = 0
$ Write sys$output "Creating File Records"
$ Write sys$output ""
$ Write sys$output ""
$!
$Create_Outfile:
$ Open/Write Outfile 'tmpfil'b.tmp
$!
$Read_List:
$! Read the first record, which contains the filespec
$ Read/End_of_File=End_of_Listing Infile Record
$ File = f$element(0," ",Record)
$ Device = f$parse(File,,,"Device","Syntax_Only")
$ Directory = f$parse(File,,,"Directory","Syntax_Only")
$ Name = f$parse(File,,,"Name","Syntax_Only")
$ Type = f$parse(File,,,"Type","Syntax_Only")
$ Version = f$parse(File,,,"Version","Syntax_Only")
$!
$! Get rid of the colon at the end of the 'device'
$ Device = Device - ":"
$!
$! Get rid of the dot at the front of the 'type'
$ Type = Type - "."
$!
$! Get rid of the semi-colon at the front of the 'version'
$ Version = Version - ";"
$! Read the second record, which contains the data
$ Read/End_of_File=End_of_Listing Infile Record
$!
$! Now check the special case where the file doesn't exist!
$!
$ IF F$LOCATE("no such file",record) .LT. F$LENGTH(record) THEN -
goto no_such_file
$!
$ IF F$LOCATE("no priv",record) .LT. F$LENGTH(record) THEN -
goto no_priv
$!
$! Now set the attributes
$!
$ file_id = f$extract(21,20,Record)
$ size = f$extract(42,6,Record)
$ created = f$extract(50,17,Record)
$ modified = f$extract(69,17,Record)
$ expires = f$extract(88,17,Record)
$ backed_up = f$extract(107,17,Record)
$ owner = f$extract(126,20,Record)
$ owner = f$element(1,",",Owner) - "]"
$!
$! Set Nil fields if any
$!
$ If 'f$locate("<",Expires) .ne. 'f$length(Expires) -
Then Expires = "NIL"
$ If 'f$locate("<",Backed_up) .ne. 'f$length(Backed_up) -
Then Backed_up = "NIL"
$ If Name .eqs. "" -
Then Name = "NIL"
$ If Type .eqs. "" -
Then Type = "NIL"
$!
$! Convert the date fields so that we can do string compares later
$!
$! Created = f$cvtime(Created)
$! Modified = f$cvtime(Modified)
$! If Expires .nes. "NIL" Then -
$! Expires = f$cvtime(Expires)
$! If Backed_up .nes. "NIL" Then -
$! Backed_up = f$cvtime(Backed_up)
$!
$!
$Write_Loop:
$ Write Outfile "|''device'| "
$ Write Outfile "|''directory'| "
$ Write Outfile "|''name'| "
$ Write Outfile "|''type'| "
$ Write Outfile "''version' " ! Must not have "|" around these or ops
$ Write Outfile "''file_id'"
$ Write Outfile "''size' " ! will not recognize it as a number
$ Write Outfile "|''created'| "
$ Write Outfile "|''modified'| "
$ Write Outfile "|''expires'| "
$ Write Outfile "|''backed_up'| "
$ Write Outfile "|''owner'| "
$ Count = Count + 1
$ if "''f$mode()'" .nes. "BATCH" Then -
write sys$output "[A''Count' File Records Created"
$ goto Read_List
$No_Such_File:
$!
$! We get here if there is a directory entry but NO corresponding file
$!
$ goto Read_List
$!
$!
$End_of_Listing:
$ Close Infile
$ Close Outfile
$ if "''f$mode()'" .eqs. "BATCH" Then Show time
$ if "''f$mode()'" .eqs. "BATCH" Then -
write sys$output "''Count' File Records created"
$!
$!
$No_File:
$ Error = "T"
$ Goto Exit
$!
$!
$No_Priv:
$ Error = "T"
$ Goto Exit
$Exit:
$!
$! Check to see if there are any files still open and close them
$!
$ If f$trnlnm("Infile") .nes. "" then Close Infile
$ If f$trnlnm("Outfile") .nes. "" then Close Outfile
$ If error then $ exit %x10000000
$ exit %x10000001
T.R | Title | User | Personal Name | Date | Lines |
---|
473.1 | Don't reformat it, write it! | PASTIS::MONAHAN | | Fri May 15 1987 01:25 | 23 |
| The sort of thing you are doing is almost certainly slow because
you are doing complex DCL processing, which means compute bound
on most CPUs.
The ODS2 structure is fairly simple, and directories can be
read directly from a high level language using RMS. The information
in addition to the file spec can be obtained by doing QIOs to the
file system. All this is exactly what the directory command itself
does to obtain the information.
I think you would have to write your own "/EXCLUDE" handling,
but unless you plan on having too fancy specifications that should
not be too hard.
The result is likely to be faster than the $ DIRECTORY command
because it is more specialised, and more maintainable than parsing
the output of the $ DIRECTORY command which may change format "in
some future release of VMS".
Send a programmer round to me some time if you need pointers
to all the documentation.
Dave
|