CURL name of the source file = name of the target file
I want to download a lot of files which have all similar names: xxx/1.jpg
, xxx/2.jpg
, xxx/3.jpg
, and so on to C:/Brawa/
.
So I write:
CURL https://example/xxx/[1-3].jpg -o C:/Brawa/#1.jpg
Now I want the name of the source file to correspond with the name of the target file: C:/Brawa/xxx/1.jpg
; C:/Brawa/xxx/2.jpg
; C:/Brawa/xxx/3.jpg
, and so on.
I use the command-line:
CURL https://example/xxx/[1-3].jpg -o --remote-name C:/Brawa/*.jpg
Something does not work, but what did I make wrong?
Solution 1:
Option values must be adjacent. With all Unix or Unix-based programs, and most C-based ones, if you specify an option with a value, like here -o C:/some/path
, you must keep the option 'flag' and its value together, you can't insert something else in between. In nearly all cases you can either use consecutive arguments like shown, or a single concatenated argument like -oC:/some/path
(for short-form) or --output=c:/some/path
(added equal-sign for long-form, i.e., two hyphens). This is more obvious in Windows (CMD) where you usually use /flag:value
all run-together, which discourages you from trying to insert anything in-between.
As you commented to harrymc's answer, --remote-name -o c:/some/path
parses correctly but doesn't work -- that's because these give conflicting instructions, and it obeys only the first one. -o c:/some/path --remote-name
would also parse, but only obey the first (which if that's a file would write every URL to the same file, leaving only the last one, and if it's a directory would fail to write at all).
Aside from Anaksunaman's answer you can change the directory to the desired location, use only --remote-name
(or -O
uppercase, either way with no value), then change the directory back. CMD supports pushd
and popd
like most Unix shells, so
pushd c:\brawa\xxx & curl https://example/xxx/[1-3].jpg -O & popd
Solution 2:
Assuming you are using an up-to-date version of curl
(version 7.73.0 or higher), you should be able to add the new --output-dir
option to specify an output directory e.g.:
curl https://example/xxx/[1-3].jpg -O --output-dir "C:/Brawa/xxx"
Note that -O
(capital oh) is the same as --remote-name
in the example above.
Up-to-date official curl
binaries for Windows are available here and option documentation for the most recent versions of curl
is available here.
Note that to dynamically create folders, you can use the --create-dirs
option to curl
(per the curl man page section for --output-dir
). However, this seems to be based on the --output-dir
option in the example above, so changing this value might require additional scripting (I was unable to get the suggestion listed in harrymc's answer to this question working correctly under Windows 7).