Jump to content


- - - - -

Rename a file from within PRO IV


16 replies to this topic

#1 Guest_Tom Haight_*

Guest_Tom Haight_*
  • Guests

Posted 08 September 2003 - 02:18 PM

Does anyone know of a way to rename a file from within PROIV or to dynamilly assign a file name?

I need to be able to assign a file name of a 2 charaget constant and mmddyy of the day it was created.

Thanks,
Tom Haight

#2 Chris Mackenzie

Chris Mackenzie

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 368 posts
  • Gender:Male
  • Location:Bristol, United Kingdom

Posted 08 September 2003 - 02:38 PM

Hi,

You can use the P4 SYSTEM command to create any filename you.
require (or to rename or copy an existing file). then you can
use the P4 ALIAS command in LOGIC-IN to your function to point
a P4 file definition to your real file

$$PHYSICAL_FILE_NAME = '/usr/textfile/BG030509.txt'
#X = SYSTEM('cp template.txt ' + $$PHYSICAL_FILE_NAME)
ALIAS('PRFMAP',$$PHYSICAL_FILE_NAME)


If you need to read a file before you construct the physical filename
you require (say to get the current year and period) then you should
pass tha data in COM vars to another function that can ALIAS to it in LOGIC-IN
because ALIAS only works there. (That is not actually true but life is
easier if you believe it is true).
The content and views expressed in this message are those
of the poster and do not represent those of any organisation.

#3 Guest_Tom Haight_*

Guest_Tom Haight_*
  • Guests

Posted 08 September 2003 - 03:17 PM

Many Thanks

#4 Cleve Haynes

Cleve Haynes

    Expert

  • Members
  • PipPipPipPip
  • 172 posts
  • Gender:Male

Posted 08 September 2003 - 03:35 PM

You can also dynamically create files using the undocumented ProIV command called "SYSF". There are lots of disclaimers about this command....

Eg.

Create a ProIsam File:
#KEYLEN = 10
#RECLEN = 1530
SYSF(&#@CREATE,'myfile.pro',#KEYLEN,#RECLEN)

Create a CISAM File:
$KEYINFO = "10@1"
#RECLEN = 50
SYSF(&#@CREATE,'myfile',&#@CISAM,#RECLEN,$KEYINFO)

Create a empty ASCII file:
SYSF(&#@CREATE,'myfile',0,0)


Cleve.

#5 Dan Shannon

Dan Shannon

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 374 posts
  • Gender:Male
  • Location:Australia

Posted 09 September 2003 - 02:35 PM

There *is* a SYSF command to do a rename :

SYSF(&#@RENAME, [some list of arguments which work])

I haven't used it in about 6 years, but it used to work in 2.0 :rolleyes: - and it was vaguely OS independent, I think.

Does anyone know how it works? Or should Tom annoy PRO-IV Support until they tell him?

Cheers

Dan Shannon

#6 Cleve Haynes

Cleve Haynes

    Expert

  • Members
  • PipPipPipPip
  • 172 posts
  • Gender:Male

Posted 09 September 2003 - 03:59 PM

Hi

Like this for a ProIsam file:

SYSF(&#@RENAME, "test.pro", "test2.pro")

Doesn't seem to work for text files though....

Cleve.

#7 Chris Mackenzie

Chris Mackenzie

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 368 posts
  • Gender:Male
  • Location:Bristol, United Kingdom

Posted 10 September 2003 - 07:59 AM

Why would anyone want to use undocumented, unsupported
features when it is perfectly simple to use the supported
methods. Is it too hard to wrap it in a global logic that would
cater for different o/s as well as rename or whatever and deal
with return codes correctly and with any file type the os can
deal with?
The content and views expressed in this message are those
of the poster and do not represent those of any organisation.

#8 Kevin Bruss

Kevin Bruss

    Expert

  • Members
  • PipPipPipPip
  • 113 posts
  • Gender:Male
  • Location:Oklahoma City, OK

Posted 15 September 2003 - 06:41 PM

For clarification, was the SYSF unsupported, or the SYSTEM call ?

I've used both... only because SYSF is harder to remember. :rolleyes:

#9 Cleve Haynes

Cleve Haynes

    Expert

  • Members
  • PipPipPipPip
  • 172 posts
  • Gender:Male

Posted 15 September 2003 - 07:38 PM

Hi

SYSF is not supported.

But it should be. I don't know why ProIV have never documented the more useful SYSF commands.

Cleve.

#10 Cleve Haynes

Cleve Haynes

    Expert

  • Members
  • PipPipPipPip
  • 172 posts
  • Gender:Male

Posted 15 September 2003 - 08:08 PM

Why would anyone want to use undocumented, unsupported
features when it is perfectly simple to use the supported
methods. Is it too hard to wrap it in a global logic that would
cater for different o/s as well as rename or whatever and deal
with return codes correctly and with any file type the os can
deal with?


You are of course right - it's probably not a good idea to use an unsupported command... :-" But given ProIV use SYSF internally, it can't have THAT many problems.... can it? :unsure:

The one issue I have with the SYSTEM command, it that it is horribly slow. Every time it is executed it has to start an OS shell which is a huge overhead. I once saw a global logic someone wrote that they probably thought was clever that was used to log information to a log file.

It did this basically:
SYSTEM('echo ' + $$_TXT + ' >> ' + $$_LOG_FILE)
Unfortunately, this was called for every record being processed. Removing it resulted in the run time going from 20 minutes to 2 minutes... Anyway, I seem to be digressing... :rolleyes:

#11 Chris Mackenzie

Chris Mackenzie

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 368 posts
  • Gender:Male
  • Location:Bristol, United Kingdom

Posted 16 September 2003 - 12:00 PM

I'm not sure how of any limitations SYSF has - other than
your comment that it had a problem with text files. Maybe
the possibility of issuing an incorrect SYSF and causing
damage is the biggest one?

I agree that issuing SYSTEM with heavy repetition is not a
good idea. I guess most apps don't need to create/rename
files very often - usually once or twice per function is enough...

But - and there's always one of those - we have a function
that needs to check the existance of a physical file on every
line of a paging screen (it's a year/period thing) and that is
sloooow.

Would be nice if we had maybe indirect access to SYSF via another
global that could prevent bad usage ...but until then...
The content and views expressed in this message are those
of the poster and do not represent those of any organisation.

#12 Rob Donovan

Rob Donovan

    rob@proivrc.com

  • Admin
  • 1,640 posts
  • Gender:Male
  • Location:Spain

Posted 16 September 2003 - 01:32 PM

Hi,

There is not 'that' bad things that you could do with the SYSF command, but really that should be up to the developer to understand and use.

And using the SYSTEM command could allow you to do anything at system level, like remove files etc... So that command is a whole lot more dangerous.

Quite a few places that I have worked at, the SYSF commands have been used. Although ProIV LTD say they are unsupported, they is no way they could (or maybe I should say 'should') change them because it would break too many systems.

Rob D.

#13 Cleve Haynes

Cleve Haynes

    Expert

  • Members
  • PipPipPipPip
  • 172 posts
  • Gender:Male

Posted 16 September 2003 - 02:35 PM

But - and there's always one of those - we have a function
that needs to check the existance of a physical file on every
line of a paging screen (it's a year/period thing) and that is
sloooow.


Well.... You could always put this in place of your system command... :-"
SYSF(&#@CHKFILE, $$FILE, #EXIST)
IF #EXIST = 0 THEN
   $FILE_EXISTS = 'Y'
ELSE
   $FILE_EXISTS = 'N'
ENDIF
It works quite nicely.

Cleve

#14 Chris Mackenzie

Chris Mackenzie

    ProIV Guru

  • Members
  • PipPipPipPipPip
  • 368 posts
  • Gender:Male
  • Location:Bristol, United Kingdom

Posted 16 September 2003 - 04:48 PM

I know I could use SYSF to check it but, like I said, I don't want to use
undocumented features...

Plus I'd have to check if it works on text file &c &c, I wonder
if it works across filesystems, does it handle files with multiple
dots in the name does it give the same return code on all
different platforms.


Lots of places I've been also used SYSF, what happens if
you issue the call with some other value as the first parameter
other than the usual set?

I see no reason why P4 should not decide to remove them
at some point - it wouldn't be the first time new releases stopped
stuff working (e.g. ALIAS change of behaviour).

To reiterate, it would be nice if P4 supported a utility to
do this sort of thing.
The content and views expressed in this message are those
of the poster and do not represent those of any organisation.

#15 Kevin Bruss

Kevin Bruss

    Expert

  • Members
  • PipPipPipPip
  • 113 posts
  • Gender:Male
  • Location:Oklahoma City, OK

Posted 01 October 2003 - 09:44 PM

If memory serves, SYSF for checking a file 1.) had a bug when checking a file without an extension. 2.) Also, it is case-sensitive so care must be used if using UPPERcased fields (ie, from a table) and checking for its unix (lowercased) equivalent. AND, 3.) there is always
the chance the permissions (in UNIX) are such that it thinks the file is not there (but is,
you just don't have permissions to it)

Here's a funky issue:

The following global update works as a nice SYSF replacement for checking an file ($$FILENAME), but it has undesirable results in 3.2 (Chess). When used, any system
call puts a "|>" on the screen when it shells out and for some reason its tacked onto
the users input field.

I use one system call to create (touch) the $$TEMPFILE,

One to put a directory listing (if applicable) of the filename into a file to be read/verified:

$$TEMPFILE = &$@~PRODATA + 'd_sychkf_' + @TERM + '.seq'
#X = SYSTEM( 'ls -d "' + $$FILENAME + '" 2>/dev/null >>' + $$TEMPFILE)

(I alias $$TEMPFILE to a sequential file and check for the existence of $$FILENAME
in the detail... The '2>/dev/null' is used just in case the file doesn't exist; it will
pipe the error message to the null device so it is not seen.)

And a third to remove the tempfile before exiting.

Any ideas on how to clear up the "|>" 's from being echo'd to screen?

If I use SYSF, I can get by, but I can't validate non-extension filenames.
Kinda screwed either way it seems.



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users