Delete all files but keep subdirectories

A forum for general AmigaOS 4.x support questions that are not platform-specific

Delete all files but keep subdirectories

Postby softwarefailure » Wed Mar 21, 2018 9:35 pm

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?
softwarefailure
 
Posts: 91
Joined: Fri Feb 14, 2014 11:29 pm

Re: Delete all files but keep subdirectories

Postby nbache » Wed Mar 21, 2018 10:01 pm

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

Re: Delete all files but keep subdirectories

Postby softwarefailure » Wed Mar 21, 2018 10:22 pm

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?
softwarefailure
 
Posts: 91
Joined: Fri Feb 14, 2014 11:29 pm

Re: Delete all files but keep subdirectories

Postby broadblues » Wed Mar 21, 2018 10:39 pm

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
User avatar
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 538
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: Delete all files but keep subdirectories

Postby softwarefailure » Wed Mar 21, 2018 10:53 pm

I guess this only works on OS4? I'm currently on MorphOS and it doesn't seem to recognize IN:
softwarefailure
 
Posts: 91
Joined: Fri Feb 14, 2014 11:29 pm

Re: Delete all files but keep subdirectories

Postby nbache » Wed Mar 21, 2018 11:31 pm

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

Re: Delete all files but keep subdirectories

Postby softwarefailure » Wed Mar 21, 2018 11:34 pm

@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.
softwarefailure
 
Posts: 91
Joined: Fri Feb 14, 2014 11:29 pm

Re: Delete all files but keep subdirectories

Postby nbache » Wed Mar 21, 2018 11:36 pm

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

Best regards,

Niels
User avatar
nbache
Beta Tester
Beta Tester
 
Posts: 1273
Joined: Mon Dec 20, 2010 8:25 pm
Location: Copenhagen, Denmark

Re: Delete all files but keep subdirectories

Postby broadblues » Thu Mar 22, 2018 12:12 am

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
broadblues
AmigaOS Core Developer
AmigaOS Core Developer
 
Posts: 538
Joined: Sat Jun 18, 2011 3:40 am
Location: Portsmouth, UK

Re: Delete all files but keep subdirectories

Postby polluks » Thu Mar 22, 2018 11:55 am

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

Next

Return to General AmigaOS

Who is online

Users browsing this forum: No registered users and 3 guests