manjesh23 manjesh23 - 7 months ago 24
Bash Question

Rename script in android (no-root)

I am trying to run a script in Android phone (no-root) to do the below task.

Get into a

camera
directory and copy all the
*.mp4
files from
Camera
to
backups
and then get into
backups
directory and to rename all the
*.mp4
to
*.nomedia
and to exit from shell.

Code

cd /
cd /storage/emulated/0/DCIM/Camera/
cp *.mp4 /storage/emulated/0/backups/
cd /
cd /storage/emulated/0/backups/
mv *.mp4 *.nomedia
exit


Output

With the file
VIDEO-12-03-2015.mp4
in
Camera
directory, this script will rename the file to
*.nomedia
but I am looking for
VIDEO-12-03-2015.nomedia
name and this is only happening to one file. Not working with multiple files if they are in
Camera
directory.

Please help.

Answer

Copy all mp4's from /storage/emulated/0/DCIM/Camera/ to /storage/emulated/0/backups/

cp /storage/emulated/0/DCIM/Camera/*.mp4 /storage/emulated/0/backups/

Trim "mp4" extension and replace it with "nomedia":

for f in /storage/emulated/0/backups/*.mp4; do 
    mv -- "$f" "${f%.mp4}.nomedia"
done