bash - Editing my If statement also ideas about to grab a files date then move file -
gnu nano 2.2.6 file: years.sh #!/bin/bash # when match not found, present nothing. shopt -s nullglob # match .wav files containing date format. files=(*[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]*.wav) if [[ ${#files[@]} -eq 0 ]]; echo "no file" fi file in "${files[@]}"; # date part part file_date='' # sleep parts. ifs="-." read -ra parts <<< "$file" t in "${parts[@]}"; # break loop if match found if [[ $t == [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] ]]; file_date=$t break fi done # if value not assigned, show error message , continue next file. # making sure there nothing in array , date before moves on before adding if statement if worked perfect files have yyyymmdd.wav format.
if [[ -z $file_date ]]; # print $6 print $5 or $7 depending on os another_file_date=`ls -l --time-style=long-iso | awk '{print $6}' | tr -d '-'` file_year=${file_date:0:4} file_month=${file_date:4:2} mkdir -p "$file_year/$file_month" echo "moving: ./"$file "to: " "./"$file_year"/"$file_month mv "$file" "$file_year/$file_month" continue fi end of new statement
file_year=${file_date:0:4} file_month=${file_date:4:2} mkdir -p "$file_year/$file_month" # -- there not interpret filenames starting - options. echo "moving: ./"$file "to: " "./"$file_year"/"$file_month mv "$file" "$file_year/$file_month" done when run code no error not move meetme files. have file called meetme93238927832783.wav... wanna grab modify date or when file created , move mive dir year/month. when run code says no file first if statement.... before added new if statement work fine yyyymmdd.wav format
modify part of script file (the if , continue part) following,
if [[ -z $file_date ]]; # print $6 print $5 or $7 depending on os another_file_date=`ls -l --time-style=long-iso | awk '{print $6}' | tr -d '-'` file_year=${file_date:0:4} file_month=${file_date:4:2} file_day=${file_date:6:2} mkdir -p "$file_year/$file_month" echo "moving: ./"$file "to: " "./"$file_year"/"$file_month mv "$file" "$file_year/$file_month"${file_year}${file_month}${file_day}.wav" continue fi and make sure print $6 correct (this test on linux, on solaris or aix number 6 should different).
Comments
Post a Comment