Why does purge not delete files?

The command below does not appear to support the deletion of all files on a remote.

rclone lsf dropbox: | xargs -d'\n' -i rclone purge dropbox:{}

It results in the following error message.

Failed to create file system for "dropbox:{filename}.txt": is a file not a directory

My understanding of the purge command is that is deletes all files and directories at a remote.

The command is expecting a directory not a file as noted in the page you linked :slight_smile:

If you want to delete a file, you'd just use delete as purge is for directories and all their contents.

Isn't the remote considered to be the root directory so shouldn't it delete files and directories with their contents?

You mean if you run:

rclone purge dropbox:

?

That would delete your entire dropbox files.

Yes and the command rclone lsf dropbox: | xargs -d'\n' -i rclone purge dropbox:{} is intended to delete all contents i.e. rclone purge dropbox:

rclone lsf lists files and you can see by the error message, you are trying to delete a file not a directory.

rclone lsf lists files and directories and given I'm parsing the list with xargs, shouldn't it be purge it?

Assuming your parse list was doing what you expected, but it's catching a file too:

felix@gemini:/opt/rclone$ rclone lsf GD: | xargs -d'\n' -i rclone lsf GD:{}
191qpocr6dhlo35vn2gk2h8gf4/
95tj3q4gj5ban13ppu0kisguco
d7pe9pia5d9a0tud31p8lkdpi0
fn0jbidpl7cqq9so46diq346so
smu5ej34ujbdoip1cm3mlk92q4/
tnvepu36qiohcun8v84ddhsam0/
rclone.log


felix@gemini:/opt/rclone$ rclone lsf GD:
Wednesday-2019-11-06/
crypt/
rclone.log

The purge is giving you an error message it's trying to delete a file so it's best to step back and see why the message is coming.

Yes, I am expecting it to list files so that they can be purged at the same time.

rclone lsf dropbox:
crypt/
testfile.txt

rclone lsf dropbox: | xargs -d'\n' -i rclone lsf dropbox:{}
bv21aq86kfd39llpd4dctdq5gk/
testfile.txt

rclone lsf dropbox: | xargs -d'\n' -i rclone purge dropbox:{}
Failed to create file system for "dropbox:testfile.txt": is a file not a directory

You can't use purge on files as it's only for directories. You'd have to use delete.

That's why the error message tells you it's a file and not a directory.

Is there a way to combine these as a single command i.e purge and delete?

If you add --dirs-only this will stop giving that error, so

rclone lsf --dirs-only dropbox: | xargs -d'\n' -i rclone purge dropbox:{}

This will leave files in the root directory only which you can delete with

rclone delete dropbox:

Thanks @ncw. Does rclone delete remote:path support redirects?

For example, would rclone delete dropbox:<filelist be allowed?

You need to use the --files-from flag to have a list of paths. These need to be relative to the root

https://rclone.org/filtering/#files-from-read-list-of-source-file-names

Thanks @ncw. I did attempt that however it returns an error. See below.

rclone deletefile --dry-run --files-from filelist.txt dropbox:

2020/01/19 05:59:02 ERROR : Attempt 1/3 failed with 1 errors and: dropbox: is a directory or doesn't exist
2020/01/19 05:59:02 ERROR : Attempt 2/3 failed with 1 errors and: dropbox: is a directory or doesn't exist
2020/01/19 05:59:02 ERROR : Attempt 3/3 failed with 1 errors and: dropbox: is a directory or doesn't exist
2020/01/19 05:59:02 Failed to deletefile: dropbox: is a directory or doesn't exist

What are the contents of the filelist.txt?

@Animosity022 - A list of files with new line characters.
For example;
file1.txt
file2.docx
file3.html

You want rclone delete instead of rclone deletefile - that should work.

@ncw, thanks. I'm looking at ways to recursively deleted selected files and hence the sourcing it from a file as opposed to a complete deletion using rclone delete.

I meant use rclone delete --files-from .... - that should work.