Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

finding a file name in this format: xxxxxxx.sed,1

Status
Not open for further replies.

telluoff

Technical User
May 14, 2014
4
US
I'm trying to clean a directory of files that have a ,1 appended to the extension. I have as yet been able to get Rexx to find this type of file name. The comma in the extension confuses Rexx. Any help would be appreciated.
 
It would be helpful if you could specify the platform and post the code what have you tried to do so far.
 
I'm using Vista Office Pro.
The program seems to assume that all characters after the '.' are the extension and when it finds a ',' it stops looking. The program finds xxxxx.jrl but when it sees a file name like xxxxx.jrl,1 it assumes that the file name is xxxxx.jrl. It can't seem find a file name with a ',' in the extension.
Code follows:

infile = 'libout.txt' /* temporary file name for the directory listing */
if stream(infile,'c','query exists') \= "" then erase infile /* erase if exists */
'dir /B *.* > 'infile /* list the current directory files */
call lineout infile /* close the temp file */
do until lines(infile) = 0 /* start the directory listing loop */
l = (linein(infile)) /* define the line variable */
parse var l . /* parse the line */

if right(l,4) = '.jrl' then erase l /* remove .jrl files */
if right(l,6) = '.jrl,1' then erase l /* remove ,1 files */
if right(l,2) = ',2' then erase l /* remove ,2 files */
if right(l,2) = ',3' then erase l /* remove ,3 files */

if right(l,1) = '%' then erase l /* remove % files */
if right(l,7) = 'SAV.lnk' then erase l /* remove the .SAV files */
if right(l,4) = '.SAV' then erase l /* remove the .SAV files */
if l = 'AUTO.brd' then erase l /* remove the AUTO.brd file */
if l = 'signoise.run' then 'rmdir /s /q' l /* remove the signoise.run dir */
end /* end the directory listing loop */
call lineout infile /* close the directory listing file */
erase infile /* delete the directory listing file */
/*cls*/ /* clear the screen */
exit
 
Does no one have an answer on how to do this?
 
What happens when you run this?

As I see it, the ,1 ,2 etc are no longer part of the extension . . .
So the process goes merrily on.

Have you run a trace?
 
It's no problem of REXX but of windows.
If you have an file file1.jrl,1 and try to erase it on command line you get an error
Code:
c:\_mikrom\Work\telluoff>erase file1.jrl,1
Could Not Find c:\_mikrom\Work\telluoff\file1.jrl
But this works:
Code:
c:\_mikrom\Work\telluoff>erase "file1.jrl,1"
 
Here is a REXX example telluoff.rex

Code:
infile [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'libout.txt'[/color]
[COLOR=#ff00ff]'dir /B *.* > '[/color]infile
[COLOR=#804040][b]do [/b][/color][COLOR=#804040][b]while[/b][/color][COLOR=#804040][b] [/b][/color][COLOR=#008080]lines([/color]infile[COLOR=#008080])[/color] [COLOR=#804040][b]\=[/b][/color] 0
  l [COLOR=#804040][b]=[/b][/color] [COLOR=#008080]linein([/color]infile[COLOR=#008080])[/color]
  [COLOR=#804040][b]if[/b][/color] [COLOR=#008080](right([/color]l[COLOR=#804040][b],[/b][/color]4[COLOR=#008080])[/color] [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'.jrl'[/color]  [COLOR=#804040][b]|[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
     [COLOR=#008080]right([/color]l[COLOR=#804040][b],[/b][/color]6[COLOR=#008080])[/color] [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'.jrl,1'[/color] [COLOR=#804040][b]|[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight] 
     [COLOR=#008080]right([/color]l[COLOR=#804040][b],[/b][/color]2[COLOR=#008080])[/color] [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]',2'[/color]     [COLOR=#804040][b]|[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
     [COLOR=#008080]right([/color]l[COLOR=#804040][b],[/b][/color]2[COLOR=#008080])[/color] [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]',3'[/color]     [COLOR=#804040][b]|[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
     [COLOR=#008080]right([/color]l[COLOR=#804040][b],[/b][/color]1[COLOR=#008080])[/color] [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'%'[/color]      [COLOR=#804040][b]|[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight] 
     [COLOR=#008080]right([/color]l[COLOR=#804040][b],[/b][/color]7[COLOR=#008080])[/color] [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'SAV.lnk'[/color][COLOR=#804040][b]|[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
     [COLOR=#008080]right([/color]l[COLOR=#804040][b],[/b][/color]4[COLOR=#008080])[/color] [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'.SAV'[/color]   [COLOR=#804040][b]|[/b][/color][highlight #ffff00][COLOR=#000000],[/color][/highlight]
     l [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'AUTO.brd'[/color][COLOR=#008080])[/color] [COLOR=#804040][b]then[/b][/color] [COLOR=#804040][b]do[/b][/color]
       [COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]'... deleting file:'[/color] l
       [COLOR=#ff00ff]'erase "'[/color][COLOR=#804040][b]||[/b][/color]l[COLOR=#804040][b]||[/b][/color][COLOR=#ff00ff]'"'[/color] [COLOR=#0000ff]/* remove files */[/color] 
   [COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]end[/b][/color]
[COLOR=#804040][b]call [/b][/color][COLOR=#008080]lineout[/color] infile
erase infile
[COLOR=#804040][b]exit[/b][/color]

Output:
Code:
c:\_mikrom\Work\telluof>dir /B
AUTO.brd
file0.jrl
file1.jrl,1
file2.jrl,2
file3.jrl,3
procfile%
procfile.%
SAV.lnk
sav_file.SAV
telluoff.rex

c:\_mikrom\Work\telluof>rexx telluoff.rex
... deleting file: AUTO.brd
... deleting file: file0.jrl
... deleting file: file1.jrl,1
... deleting file: file2.jrl,2
... deleting file: file3.jrl,3
... deleting file: procfile%
... deleting file: procfile.%
... deleting file: SAV.lnk
... deleting file: sav_file.SAV

c:\_mikrom\Work\telluof>dir /B
telluoff.rex
 
mikrom,

The quoted file name does not work:
c:\_mikrom\Work\telluoff>erase "file1.jrl,1"

But your following code does!

I believe the secret was the inclusive or's in the
erase statement and the position of the single and
double quotes.

I've been looking at this for a long time.
Thank you very much. You're now my Hero.

telluoff

 
telluoff said:
The quoted file name does not work
It works, try it: Create a file your_filename.jrl,1 in a folder.
Then start command line, change to the folder and execute command
erase "your_filename.jrl,1"
It must work.

telluoff said:
I believe the secret was the inclusive or's in the
erase statement and the position of the single and
double quotes.
There are not inclusive ORs. In REXX the operator | means OR, but the operator || means string concatenation - see for example here
So you can create the erase command either with || or without it:

Code:
file_name [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'file1.jrl,1'[/color]

erase_command [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'erase "'[/color]file_name[COLOR=#ff00ff]'"'[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]'erase_command : '[/color] erase_command

erase_command [COLOR=#804040][b]=[/b][/color] [COLOR=#ff00ff]'erase "'[/color] [COLOR=#804040][b]||[/b][/color] file_name [COLOR=#804040][b]||[/b][/color] [COLOR=#ff00ff]'"'[/color]
[COLOR=#804040][b]say[/b][/color] [COLOR=#ff00ff]'erase_command : '[/color] erase_command
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top