Delete all files but keep subdirectories

A forum for general AmigaOS 4.x support questions that are not platform-specific
softwarefailure
Posts: 112
Joined: Fri Feb 14, 2014 10:29 pm

Delete all files but keep subdirectories

Post 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?
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1714
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: Delete all files but keep subdirectories

Post 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
softwarefailure
Posts: 112
Joined: Fri Feb 14, 2014 10:29 pm

Re: Delete all files but keep subdirectories

Post 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?
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Delete all files but keep subdirectories

Post 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
softwarefailure
Posts: 112
Joined: Fri Feb 14, 2014 10:29 pm

Re: Delete all files but keep subdirectories

Post by softwarefailure »

I guess this only works on OS4? I'm currently on MorphOS and it doesn't seem to recognize IN:
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1714
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: Delete all files but keep subdirectories

Post 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
softwarefailure
Posts: 112
Joined: Fri Feb 14, 2014 10:29 pm

Re: Delete all files but keep subdirectories

Post 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.
User avatar
nbache
Beta Tester
Beta Tester
Posts: 1714
Joined: Mon Dec 20, 2010 7:25 pm
Location: Copenhagen, Denmark
Contact:

Re: Delete all files but keep subdirectories

Post by nbache »

I know, but it was also a response for broadblues who gave an example with ALL.

Best regards,

Niels
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 600
Joined: Sat Jun 18, 2011 2:40 am
Location: Portsmouth, UK
Contact:

Re: Delete all files but keep subdirectories

Post 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
User avatar
polluks
Posts: 55
Joined: Tue May 19, 2015 6:30 pm
Location: Germany
Contact:

Re: Delete all files but keep subdirectories

Post 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
Post Reply