Answer the question
In order to leave comments, you need to log in
How to find a file through cmd and replace it with another one?
Hello!
Please tell me how to use the bat file to search for a file on all disks and replace it with your own? For example, I have a 1.txt file (it is somewhere on one of the C, D or H drives) and I need to somehow automatically find it and completely replace it with 2.txt. That is, remove it and replace it with 2.txt
Answer the question
In order to leave comments, you need to log in
dir /s/b 1.txt
will search through all subfolders. For each disk you will need to call.
You can iterate through all found using for.
But be warned, this will be VERY slow.
for /f "tokens=*" %%i in ('fsutil.exe fsinfo drives') do set _list=%%i
for %%i in (%_list%) do (forfiles.exe /p %i:\temp /s /m test.txt /c "cmd.exe /c copy /y c:\windows\win.ini @path")
forfiles.exe /?
FORFILES [/P <путь>] [/M <маска_поиска>] [/S]
[/C <команда>] [/D [+ | -] {dd.MM.yyyy | dd}]
Описание.
Выбор файла (или набора файлов) и выполнение команды
с этим файлом. Программа полезна для пакетных заданий.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question