Listing only file name of files in remote

While using rclone lsf --files-only it produces

rootfolder/folder2/filename1.pdf
rootfolder/folder3/filename2.pdf
rootfolder/folder4/folder5/filename3.pdf

I would like to have just the list of files

filename1.pdf
filename2.pdf
filename3.pdf

While it is possible to filter the output of rclone, it is complex.

I read all I could but did not find a native rclone only solution.
Is there any way to do that?

I am aware that there can be files with same name. The ideal solution would be to have path and filename, but not in the same string …

TIA

Rclone doesn’t do that right now. Should be easy to parse though.

rclone lsf remote: --files-only --recursive 2>&1 | sed 's!.*/!!'
1 Like

Thanks!

being a windoze I always forget about sed… I was trying to parse it using just pure cmd commands…

1 Like

What are you doing with just the file names?

I am feeding filename and its mega publiclink to a sqlite3 to handle assets, so I can send a pdf with name and link to relatives… So, end product is not needing the full path, althought I will keep it in the DB as reference. I use md5 of filename as index so removing the path is interesting, althougth this is transitory cause I plan to use the file md5 instead.

Easier: basename -a $(rclone lsf --files-only --recursive remote:/path/)

@chiraag
Windows?

Unfortunately, I haven't really used Windows in a long time. According to this, you should be able to use the variable %~nx<variable name>. And according to this, something like this should work:

for /f %%x in ('rclone lsf --files-only --recursive remote:/path/') do echo %~nxx

Keep in mind that I have absolutely not tested this since I haven't let Windows touch my computer for a long time now.

@chiraag

ups, my question was fully unclear; I was meaning if there was any baseline implementation for windows.
But your comment pointed me to a nice discussion here https://stackoverflow.com/questions/3432851/dos-bat-file-equivalent-to-unix-basename-command with full explanation of how to achieve the desired outcome and moreover a pointer to a baseline in windows https://www.mkssoftware.com/docs/man1/basename.1.asp

Besides I found a clean interesting approach here - https://gist.github.com/Ciantic/092ec71fa76429cebd666bb6c789d089 (need to check if covers non-ansi...)

I already tried to use for loops and similar elements, but, inside bats and with spaces in filenames and non-ansi chars and ... blablabla... I was unable to find a safe way to implement it... Just chopping an chopping in going down levels (I went up to four subdirectories, then I stopped), as I was unable to make the recursivity work...

Thanks!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.