D
D
diman552017-07-29 04:39:59
Command line
diman55, 2017-07-29 04:39:59

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

2 answer(s)
S
Stalker_RED, 2017-07-29
@Stalker_RED

dir /s/b 1.txtwill 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.

0
074909, 2018-07-11
@074909

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 question

Ask a Question

731 491 924 answers to any question