| TIP: Click on subject to list as thread! | ANSI |
| echo: | |
|---|---|
| to: | |
| from: | |
| date: | |
| subject: | Help with REXX program |
Hello Herbert,
HB> Say DIR_B contains FILE1, FILE1.001 and FILE2. Now I run the
HB> script. As the copy from DIR_A starts, it sees that FILE1
HB> already exists, so it trys for FILE1.001. It finds that this
HB> also exist, so it goes to FILE1.002. This doesn't exist, so it
HB> copies FILE1 from DIR_A to the name FILE1.002 in DIR_B. Now it
HB> does the same for FILE2, and finding that this exist in DIR_B
HB> also, renames it to FILE2.001, and copies it accordingly.
Try this:-
==============8< Cut here 8< ===================
/* All REXX files need a comment on the FIRST LINE */
/* name it '.cmd' eg 'fcpy.cmd' */
/* firstly load the external Rexx functions package -
needed for 'sysfiletree' */
call RxFuncAdd 'SysLoadFuncs', 'REXXUTIL', 'Sysloadfuncs'
call Sysloadfuncs
/* enter actual names for the dirs here including drive & path
- note the *.* for the filespec. */
sourcespec = "DIR_A\*.*"
targetdir = "DIR_B\"
/* get sysfiletree to put the filenames in 'allfiles' */
call sysfiletree sourcespec, 'allfiles', 'FO'
/* the number of files found will be in 'allfiles.0' */
do tt = 1 to allfiles.0
/* this routine renames and renumbers the files */
call namefile
/* then use OS/2's copy command to copy the files to
the new filenames */
'copy' allfiles.tt thisfile
end /* do */
exit
/*-------------------------------------------*/
NAMEFILE:
/* firstly, get rid of the old directory name, then add the new one */
thisfile = allfiles.tt
namestart = lastpos('\', allfiles.tt )
thisfile = right(allfiles.tt, (length(allfiles.tt) - namestart))
thisfile = targetdir||thisfile
/* if this file already exists add a number to it */
fileisthere = stream(thisfile,'c','query exists')
if fileisthere \= "" then do
thisfile = thisfile||'.001'
/* if it still exists, loop through the numbers to 999 'til it doesn't */
fileisthere = stream(thisfile,'c','query exists')
if fileisthere \= "" then do fext = 1 to 999
pw = length(thisfile)-length(fext)+1
thisfile =overlay(fext,thisfile,pw)
if stream(thisfile,c,query exists) = "" then leave
end /* do */
end /* do */
return
/*-----------------------------------------*/
==============8< Cut here 8< ===================
It works here.
As it is, the copy command echos its results to the screen - to turn
this off put '{at}echo off' (quotes included) near he top of the file.
Caveats - it doesn't handle more than 1000 files of the same name. If
the source files have an extension present, it'll give them another one.
eg file.txt.001 etc
Colin.
___
X KWQ/2 1.2f X If you think women aren't explosive, try dropping one.
--- Maximus/2 2.01wb
* Origin: DoNoR/2,Woking UK (0483-725167) (2:440/4)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: 440/4 141/209 270/101 396/1 3615/50 229/2 12/2442 711/409 54/54 @PATH: 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™.