0

I am trying to write a shell script that takes files from a cd drive and moves them onto an external USB drive. I am running it on windows 11 in the git shell for windows.
Part of the script is to change the .CDA files from the cd drive to a .mp3 file and I have not been able to get this to work.

This is the best answer I found but it does not work:
ffmpeg -i *.cda *.mp3
This Is the rest of my script if it helps

cd /d/
mkdir $1
cd /e/
cp *.cda /d/$1
cd /d/$1
ffmpeg -i *.cda *.mp3
ls
Compo
  • 36,585
  • 5
  • 27
  • 39
  • I have not touched a CD in years but I think those .cda files are faked by the shell? A redbook CD does not contain files... – Anders Aug 29 '22 at 00:46
  • I am voting to reopen because this question is partly about the correct use of `ffmpeg`, which I agree is off topic here, but mostly about shell scripting, which is certainly on topic here. – joanis Aug 29 '22 at 13:20
  • 1
    @uncletall's answer is the right idea, but you need a Bash loop if you're working in the Git shell. This might work: `for f in *.cda; do ffmpeg -i "$x" "${x%.cda}.mp3"; done`. The issue with your solution is that ffmpeg takes just one input/output file pair at a time, so you have to loop over your files in the shell. – joanis Aug 29 '22 at 13:24

1 Answers1

0

You can do this simply using a for loop and variable substitutions to extract the filename without extension. See below the help for relevant output.

You loop code:

for %f in (*.cda) do ffmpeg -i %f %~nf.mp3

Here the %~nf will use the filename, without extension, in the variable f and you can append your extension

In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

%~I         - expands %I removing any surrounding quotes (")
%~fI        - expands %I to a fully qualified path name
%~dI        - expands %I to a drive letter only
%~pI        - expands %I to a path only
%~nI        - expands %I to a file name only
%~xI        - expands %I to a file extension only
%~sI        - expanded path contains short names only
%~aI        - expands %I to file attributes of file
%~tI        - expands %I to date/time of file
%~zI        - expands %I to size of file
%~$PATH:I   - searches the directories listed in the PATH
               environment variable and expands %I to the
               fully qualified name of the first one found.
               If the environment variable name is not
               defined or the file is not found by the
               search, then this modifier expands to the
               empty string
uncletall
  • 6,609
  • 1
  • 27
  • 52
  • Please note from the question body, uncletall, "I am running it on windows 11 in the git shell for windows." I have changed the tags now to reflect that, but having done so, your answer may no longer be valid. Please check. – Compo Aug 29 '22 at 11:38