Page 1 of 2

Delete all files but keep subdirectories

Posted: Wed Mar 21, 2018 8:35 pm
by softwarefailure
Is it possible to delete all files with the DELETE command but keep subdirectories? I've tried

Code: Select all

delete sys:test/#?
but it will delete subdirectories if they're empty. I'd like to keep them. Only files should be deleted from sys:test. Is it possible?

Re: Delete all files but keep subdirectories

Posted: Wed Mar 21, 2018 9:01 pm
by nbache
Do you only need to delete one level, or do you need recursive descent into subdirectories?

If the former, you could do something like:

List FILES LFORMAT "delete *"%s*" quiet" | execute IN:

(the pair of *" around the %s are necessary to handle file names with spaces).

If you need multilevel recursion, you probably need to script a solution e.g. with ARexx.

Best regards,

Niels

Re: Delete all files but keep subdirectories

Posted: Wed Mar 21, 2018 9:22 pm
by softwarefailure
Thanks, I need just one level. So where does the directory to be scanned go? Should IN: be substituted by the directory to be scanned?

Re: Delete all files but keep subdirectories

Posted: Wed Mar 21, 2018 9:39 pm
by broadblues
IN: is an "assign" that refers to the Input stream. ie STDIN

put the directory to be scanned anywhere before the pipe, but either last or just after list makes sense.

BTW adding 'all'

Code: Select all

6.AmigaOS4:> list all files LFORMAT "DELETE %s%s" RAM: | execute IN:
will do recursion if needed

eg replaceing execute wit 'type' for testing.

Code: Select all

6.AmigaOS4:> list all files RAM: LFORMAT "DELETE %s%s" | type IN:
DELETE RAM:MultiViewer.debug
DELETE RAM:ao.log
DELETE RAM:Disk.info
DELETE RAM:T/ConsoleIndex16959
DELETE RAM:T/ConsoleAttr16959
DELETE RAM:T/ConsoleText16959
DELETE RAM:T/YAMm0000001c-p1.1
DELETE RAM:T/YAMr0000001c-p0.txt
DELETE RAM:T/notifications.log
DELETE RAM:T/svn_info.txt
DELETE RAM:T/usb.log

Re: Delete all files but keep subdirectories

Posted: Wed Mar 21, 2018 9:53 pm
by softwarefailure
I guess this only works on OS4? I'm currently on MorphOS and it doesn't seem to recognize IN:

Re: Delete all files but keep subdirectories

Posted: Wed Mar 21, 2018 10:31 pm
by nbache
That's probably correct. I believe it was added either in the early OS4 days or even back in the 3.9 or 3.5 days, IIRC around the time where also a number of commands which had previously been disk-based, were built into the Shell.

The workaround would be to redirect the output from the List part into a file and then execute that, i.e. two commands instead of a one-liner.

And yes, of course there is the ALL parameter, sorry, I had forgotten about that.

Best regards,

Niels

Re: Delete all files but keep subdirectories

Posted: Wed Mar 21, 2018 10:34 pm
by softwarefailure
@Niels: The ALL parameter isn't needed for my case because I don't want to recurse into subdirectories so I don't need ALL.

Re: Delete all files but keep subdirectories

Posted: Wed Mar 21, 2018 10:36 pm
by nbache
I know, but it was also a response for broadblues who gave an example with ALL.

Best regards,

Niels

Re: Delete all files but keep subdirectories

Posted: Wed Mar 21, 2018 11:12 pm
by broadblues
softwarefailure wrote:I guess this only works on OS4? I'm currently on MorphOS and it doesn't seem to recognize IN:
IN: only works on OS4 if there is pipe '|' involved.

If IN: isn;t recognised on MOS you could use an explict pipe intead perhaps

Code: Select all

list files LFORMAT "DELETE %s%s" RAM: TO PIPE:mypipe | execute PIPE:mypipe
(removed the all :-))

Again testing with type instead of execute

Code: Select all

11.AmigaOS4:> list files LFORMAT "DELETE %s%s" RAM: TO PIPE:mypipe | type PIPE:mypipe
DELETE RAM:FTP.log
DELETE RAM:MultiViewer.debug
DELETE RAM:ao.log
DELETE RAM:Disk.info

Re: Delete all files but keep subdirectories

Posted: Thu Mar 22, 2018 10:55 am
by polluks
nbache wrote:That's probably correct. I believe it was added either in the early OS4 days or even back in the 3.9 or 3.5 days, IIRC around the time where also a number of commands which had previously been disk-based, were built into the Shell.
Well, it's a bit older http://oldwww.nvg.ntnu.no/amiga/amigafa ... AQ_10.html