Welcome, Autel Pilots!
Join our free Autel drone community today!
Sign up

Rename X-Star Log Files

TomKnAL

Well-Known Member
Joined
Aug 29, 2016
Messages
91
Reaction score
22
Age
64
I have suggested that Autel either revise or add an option to use date/time as part of the media file names. I have developed a bash script that will rename files. I like to copy the media files to another disk and I would sometimes have name collisions.

Code:
rename_w_time
Rename MAX_0001.MOV -> M_160730_101024_001.MOV
Rename MAX_0002.MOV -> M_160730_101845_002.MOV
...
Rename MAX_0012.JPG -> M_160730_194457_012.JPG
Rename MAX_0013.JPG -> M_160730_194513_013.JPG
Rename MAX_0014.MOV -> M_160730_194938_014.MOV
Rename MAX_0015.JPG -> M_160730_195013_015.JPG
This is the script, which should work with Macs and Linux machines. It will work on PCs with a bash shell.

Code:
#!/bin/bash
# This script will check a specified directory for any X-Star media files
# then rename each file based on the mtime of the file.

# this needs to point to the location of script:
RENAME=/Volumes/T1TB_1/XStar/bin/rename_w_time.bash

# presume file name format
file_re="MAX_.([0-9]{3})\.(JPG|MP4|MOV|***)"

dir=$1
cd ${dir:=.}

flist=`ls`

declare -a dirs

for fr in $flist ; do
    if [[ -f $fr ]] ; then
        if [[ $fr =~ $file_re ]] ; then
            seqn=${BASH_REMATCH[1]}
            sufx=${BASH_REMATCH[2]}
            stat=(`stat -t %y%m%d_%H%M%S $fr`)
            ## echo ${stat[@]}
            eval mdate=${stat[9]}
            tgt=M_${mdate}_$seqn.$sufx
            ## echo -n "mv $fr $tgt - "
            mv $fr $tgt
            echo "Rename $fr -> $tgt"
        fi
    elif [[ -d $fr ]] ; then
        dirs+=($fr)
    else
        echo "Skip $fr"
        # sleep 5
    fi
done

for adir in "${dirs[@]}" ; do
    echo -e "\nProcess $adir\n"
    $RENAME $adir
done
 

Latest threads

Members online

Forum statistics

Threads
3,974
Messages
37,799
Members
2,507
Latest member
Wbrock001