Doing a scripted batch rename of many files on a WebDAV (e.g. Nextcloud) share?

41 Views Asked by At

This is a script which allows you to use standard UNIX tools to do scripted renames of many files in a folder saved on a WebDAV resource, e.g. Nextcloud, without having to mount the WebDAV resource as a filesystem. This specific implementation reformats the timestamps in the filenames, but you can use it to do anything you wish.

This requires the KDE Desktop (www.kde.org) or at least their client libraries to be installed. You can also use e.g. the KDE Neon Linux distribution, or Kubuntu, or any of their 'Live' variants if you don't have it installed.

Example: 23-11-01 07-14-34 2142.jpg will become 2023.11.01 07.14.34 2142.jpg

I hope this will help somebody. It helped me quite a lot :-)

1

There are 1 best solutions below

0
Jens On
# First, set the base URL. You'll need to tweak this.
URL="webdavs://my-hosting-service.net/remote.php/dav/files/[email protected]/Photos/2023/12"

# Then, use KDE's `kioclient` tool to do the listing and renaming.
kioclient ls "$URL" | grep -e '^23-' | while read X ; do
   NEW="$(echo $X | sed -e 's,-,.,g' | sed -e 's/^23./2023./g')"
   echo "$X -> $NEW"
   kioclient mv "$URL/$X" "$URL/$NEW"
done