L
L
lazix2021-04-06 09:51:15
cmd/bat
lazix, 2021-04-06 09:51:15

How to download and rename multiple files automatically in CMD?

You need to download several files from the links and automatically rename them to *filename*-MMDD.ext
In order for the download to proceed in parallel, I call wget in the bat file via start, and then rename it.

start wget "https://site.com/filename.ext" --secure-protocol=auto -O "C:\filename.ext"
set CURDATE=%date%
ren A:\filename.ext filename-%CURDATE:~3,2%%CURDATE:~0,2%.ext

The problem is that the file is downloaded for some time, and the bat is executed and closed (each wget is running in a separate process), so at the end when renaming, I get an error:
The process cannot access the file, because this file is occupied by another process.

Slip filename-%CURDATE:~3.2%%CURDATE:~0.2%.ext directly into wget does not work, it does not understand the following: Invalid argument.
Tell me, please, how to solve?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pumpkinm, 2021-04-06
@lazix

Firstly, you first have C :\filename.ext, and then A :\filename.ext
Secondly, why currdate? Take immediately date. Here's a quote)) :

start wget "https://site.com/filename.ext" --secure-protocol=auto -O "C:\filename-%date:~3,2%%date:~0,2%.ext"

Works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question