| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Storing directories |
Andrew Clegg wrote in a message to All:
AC> Using Rexx or a simple cmd file, I want to be able to
AC> store the name of my current drive and directory so
AC> that I can change back to the same place after
AC> executing a program that needs to be run from a
AC> particular directory.
Below are 2 RExx scripts that do,
>>>>>>>>>>>--------- pushd.cmd
/* PUSHD */
/* written: Ken Neighbors sometime before 13 May 93 */
/* revised: Greg Roelofs 19 May 93 added +n option */
/* revised: Ken Neighbors 30 May 93 comments, bug fixes, beautify */
parse arg Argument rest
if ( rest '' ) then do
say 'pushd: Too many arguments.'
exit 1
end
DirStack = value('PUSHD',,'OS2ENVIRONMENT')
if ( Argument == '' ) then do
/*
* first case: no argument--swap top two directories
*/
if ( DirStack == '' ) then do
say 'pushd: No other directory.'
exit 1
end
else do
parse var DirStack NewDir OtherDirs
CurrentDir = _beaut(directory())
NewDirVerify = _beaut(directory(NewDir))
if ( NewDirVerify == '' ) then do
say insert(NewDir,': No such directory.')
/* get rid of bad directory (unlike csh pushd) */
DirStack = OtherDirs
call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
say CurrentDir DirStack
exit 2
end
else do
/* place (old) current directory at beginning of stack */
DirStack = insert(OtherDirs,CurrentDir,length(CurrentDir)+1)
call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
say NewDirVerify DirStack
end
end
end
else do
/*
* second case: argument is "+n"--do cyclic rotation by n positions
*/
if ( substr(Argument,1,1) == '+' ) then do
n = substr(Argument,2)
/* check that n is a whole number, greater than zero, less than dirs */
if ( \datatype(n,'Whole number') | (n < 1) ) then do
say 'pushd: Invalid cyclic parameter'
exit 3
end
NumDirs = words(DirStack) /* plus one: current dir */
if (n > NumDirs) then do
say 'pushd: Directory stack not that deep'
exit 3
end
CurrentDir = _beaut(directory())
/* use subword() to parse according to n */
NewDir = subword(DirStack,n,1) /* CurrentDir not in DirStack yet */
NewDirVerify = _beaut(directory(NewDir))
if ( NewDirVerify == '' ) then do
say insert(NewDir,': No such directory.')
/* get rid of bad directory (unlike csh pushd) */
DirStack = delword(DirStack,n,1)
call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
say CurrentDir DirStack
exit 2
end
else do
/* directory exists and we're now in it: shift DirStack around */
/* CurrentDir is no longer current--it's the old directory */
/* Warning: this is confusing */
DirStack = insert(DirStack,CurrentDir,length(CurrentDir)+1)
firsthalf = subword(DirStack,1,n)
lasthalf = subword(DirStack,n+1)
DirStack = insert(firsthalf,lasthalf,length(lasthalf)+1)
/* get rid of now current dir, "NewDir" */
DirStack = delword(DirStack,1,1)
call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
say NewDirVerify DirStack
end
end
/*
* third case: argument is new directory--switch to it and add to stack
*/
else do
NewDir = translate(Argument,'\','/')
CurrentDir = _beaut(directory())
NewDirVerify = _beaut(directory(NewDir))
if ( NewDirVerify == '' ) then do
say insert(NewDir,': No such directory.')
exit 2
end
DirStack = insert(DirStack,CurrentDir,length(CurrentDir)+1)
call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
say NewDirVerify DirStack
end
end
exit 0
>>>>>>>>>>>--------- popd.cmd
/* POPD */
/* written: Ken Neighbors sometime before 13 May 93 */
/* revised: Ken Neighbors 30 May 93 +n, comments, bug fixes, beautify */
parse arg Argument rest
if ( rest '' ) then do
say 'popd: Too many arguments.'
exit 1
end
DirStack = value('PUSHD',,'OS2ENVIRONMENT')
/*
* first case: argument is "+n"--delete nth entry from stack
*/
if ( substr(Argument,1,1) == '+' ) then do
n = substr(Argument,2)
/* check that n is a whole number, greater than zero, less than dirs */
if ( \datatype(n,'Whole number') | (n < 1) ) then do
say 'popd: Invalid cyclic parameter'
exit 3
end
NumDirs = words(DirStack) /* plus one: current dir */
if (n > NumDirs) then do
say 'popd: Directory stack not that deep'
exit 3
end
DirStack = delword(DirStack,n,1)
call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
CurrentDir = _beaut(directory())
say CurrentDir DirStack
end
/*
* second case: no argument--pop top directory
*/
else do
parse var DirStack NewDir DirStack
if ( NewDir == '' ) then do
/* The stack is empty */
say 'There is no directory to pop.'
exit 1
end
else do
/* Switch current directory with the one on top of stack, NewDir */
NewDirVerify = _beaut(directory(NewDir))
if ( NewDirVerify '' ) then do
call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
say NewDirVerify DirStack
end
else do
/* could not change to NewDir, so just delete it from stack */
say insert(NewDir,': No such directory.')
call value 'PUSHD',DirStack,'OS2ENVIRONMENT'
CurrentDir = _beaut(directory())
say CurrentDir DirStack
exit 2
end
end
end
exit 0
>>>>>>>>>>>---------
Lionel.
--- timEd/2-B11
* Origin: Nemesis... the OS/2 Resource (604) 383-0493 (1:340/303)SEEN-BY: 12/2442 54/54 620/243 624/50 632/348 640/820 690/660 711/409 410 413 SEEN-BY: 711/430 807 808 809 934 942 949 712/353 623 713/888 800/1 @PATH: 340/303 41 1 3615/50 229/2 12/2442 711/409 54/54 711/808 809 934 |
|
| SOURCE: echomail via fidonet.ozzmosis.com | |
Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.