Advertisement

10.10.2008 at 11:22AM PDT, ID: 23805056 | Points: 500
[x]
Attachment Details

Use Bash script to move and edit files with spaces in their names.

Asked by toben88 in Bourne-Again Shell (bash), Shell Scripting

Tags:

I have a bash script that loops every 5 minutes. It looks through a folder grabs all the file names - encodes the files to a new video format and moves them.

This works great except for all files with spaces in the name.  Help me find out how to properly account for spaces in the names without renaming them.

So the script sees ../encode/mp4/movie.wmv encodes it in ../encoding/mp4/ then moves file to ../encoded/mp4/movie.mp4
Then it does all the other files. If there are no files it waits 5 minutes and tries again.

Again, I need help accounting for files with spaces this script does not handle spaces in the filename correctly.
 
Thank you!Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
#!/bin/bash
while true ; do
rm -f /home/smartdata/www/files/encode/mp4/*.log
for movie in /home/smartdata/www/html/files/encode/mp4/*.* ; do
    NEWNAME=`basename $movie`
    ORIGINALPATH=$movie
    NEWNAME="${NEWNAME%.*}.mp4"
    NEWPATH=/home/smartdata/www/html/files/encoding/mp4/$NEWNAME
    FINALPATH=/home/smartdata/www/html/files/encoded/mp4/$NEWNAME
    COPYPATH=/home/smartdata/www/html/files/encode/mp4/copy/$NEWNAME
 
    echo Processing $movie
    echo -- New name is $NEWNAME
    echo -- New path is $NEWPATH
    echo -- Final path is $FINALPATH
    echo -- Original path is $ORIGINALPATH
ffmpeg -i "$movie" -y -an -pass 1 -vcodec libx264 -s 416x312 -b 500kb -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me epzs -subq 1 -trellis 0 -refs 1 -bf 16 -b_strategy 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 500kb -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 "$NEWPATH"
 
ffmpeg -i "$movie" -y -acodec libfaac -ab 64k -pass 2 -vcodec libx264 -s 416x312 -b 500kb -flags +loop -cmp +chroma -partitions +parti8x8+parti4x4+partp8x8+partb8x8 -flags2 +brdo+dct8x8+wpred+bpyramid+mixed_refs -me umh -subq 6 -trellis 1 -refs 4 -bf 16 -directpred 3 -b_strategy 1 -bidir_refine 1 -coder 1 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -bt 500kb -rc_eq 'blurCplx^(1-qComp)' -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 "$NEWPATH"
mv $ORIGINALPATH /home/smartdata/www/html/files/encode/mp4/finished/
mv $NEWPATH $FINALPATH
done
echo 5
echo 4
echo 3
echo 2
echo 1
echo Waiting 5 minutes
sleep 300 #wait 5 min
echo Done Waiting 5 minutes
done
[+][-]10.10.2008 at 11:30AM PDT, ID: 22689365

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.10.2008 at 12:41PM PDT, ID: 22690018

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.10.2008 at 02:04PM PDT, ID: 22690782

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.10.2008 at 02:30PM PDT, ID: 22690954

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.10.2008 at 02:36PM PDT, ID: 22690980

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.10.2008 at 03:56PM PDT, ID: 22691349

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.10.2008 at 04:02PM PDT, ID: 22691383

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.15.2008 at 10:55AM PDT, ID: 22723744

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.15.2008 at 10:57AM PDT, ID: 22723765

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628