<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; CMD/BAT: Найти файл, изменить и сохранить]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=9495&amp;type=atom" />
	<updated>2014-04-17T15:45:53Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=9495</id>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Найти файл, изменить и сохранить]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=81906#p81906" />
			<content type="html"><![CDATA[<p>Кстати, получить фиксированные диски можно и так:<br /></p><div class="codebox"><pre><code>@echo off
  setlocal
    for /f &quot;tokens=3 delims= &quot; %%i in (&#039;echo list volume^
      ^| diskpart ^| findstr /ir ђ §¤Ґ«&#039;) do (
      for /f %%j in (&#039;2^&gt;nul dir /a-d /b /s %%i:\file.xml&#039;) do (
        copy &quot;%%j&quot; &quot;%%~dpnj.bak&quot;&gt;nul
        ...
      )
    )
  endlocal
exit /b</code></pre></div><p>Или, если у пользователя нет прав администратора:<br /></p><div class="codebox"><pre><code>@echo off
  setlocal enabledelayedexpansion
    ::getting harddrives
    set &quot;i=0&quot;
    for /f &quot;tokens=1,3&quot; %%i in (&#039;reg query HKLM\SYSTEM\MountedDevices^
     ^| findstr /ir DosDevices ^| sort&#039;) do (
      set &quot;chk=%%~j&quot;
      if &quot;!chk:~0,2!&quot; equ &quot;EC&quot; (
        for /f &quot;tokens=2 delims=\&quot; %%k in (&quot;%%i&quot;) do (
          set &quot;arr.!i!=%%k\&quot; &amp; set /a &quot;i+=1&quot;
        )
      )
    )
    ::searching file
    set /a &quot;len=%i% - 1&quot;
    for /l %%i in (0, 1, !len!) do (
      for /f %%j in (&#039;2^&gt;nul dir /a-d /b /s !arr.%%i!file.xml&#039;) do (
        copy &quot;%%j&quot; &quot;%%~dpnj.bak&quot;&gt;nul
        ...
      )
    )
  endlocal
exit /b</code></pre></div><p>Вариантов много.</p>]]></content>
			<author>
				<name><![CDATA[greg zakharov]]></name>
			</author>
			<updated>2014-04-17T15:45:53Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=81906#p81906</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Найти файл, изменить и сохранить]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=81893#p81893" />
			<content type="html"><![CDATA[<p>Еще один вариант без использования wmic.<br /></p><div class="codebox"><pre><code>@echo off
  setlocal enabledelayedexpansion
    set &quot;map=ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;
    for /l %%i in (0, 1, 25) do (
      set &quot;drv=!map:~%%i,1!&quot;
      @!drv!: 2&gt;nul &amp;&amp; (
        for /f &quot;tokens=*&quot; %%j in (&#039;2^&gt;nul dir /a-d /b /s !drv!:file.xml&#039;) do echo &quot;%%j&quot;
      )
    )
  endlocal
exit /b</code></pre></div><p>Правда стоит иметь в виду, что подобный подход, в отличии от использования mountvol или тормознутого wmic, не игнорирует диски, созданные командой subst.</p>]]></content>
			<author>
				<name><![CDATA[greg zakharov]]></name>
			</author>
			<updated>2014-04-17T09:26:58Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=81893#p81893</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Найти файл, изменить и сохранить]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=81869#p81869" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>@echo off
for /f &quot;tokens=2 delims==:&quot; %%h in (&#039;
 wmic logicaldisk get Name /value
&#039;) do (
 for /f &quot;delims=&quot; %%i in (&#039;dir &quot;%%h:\file.xml&quot; /a-d /b /s&#039;) do (
  echo %%i
  copy &quot;%%i&quot; &quot;%%~i.bak&quot;&gt;nul
  (
  for /f &quot;tokens=1* delims=:&quot; %%j in (&#039;findstr /n &quot;^&quot; &quot;%%i.bak&quot;&#039;) do (
   if &quot;%%k&quot;==&quot;12345=false&quot; (
    echo 12345=true
    ) else (
    echo:%%k
    )
   )
  )&gt;&quot;%%i&quot;
  )
 )
pause&gt;nul
exit /b</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Yury]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30230</uri>
			</author>
			<updated>2014-04-17T06:47:10Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=81869#p81869</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Найти файл, изменить и сохранить]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=81865#p81865" />
			<content type="html"><![CDATA[<div class="codebox"><pre><code>@echo off
  setlocal
    set &quot;itm=%%ifile.xml&quot;
    for /f &quot;delims= &quot; %%i in (&#039;mountvol ^| findstr /ir [a-z]:\\&#039;) do (
      for /f %%j in (&#039;2^&gt;nul dir /a-d /b /s %itm%&#039;) do (
        echo %%j
      )
    )
  endlocal
exit /b</code></pre></div>]]></content>
			<author>
				<name><![CDATA[greg zakharov]]></name>
			</author>
			<updated>2014-04-17T05:15:20Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=81865#p81865</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Найти файл, изменить и сохранить]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=81863#p81863" />
			<content type="html"><![CDATA[<p>Именно так.</p>]]></content>
			<author>
				<name><![CDATA[Yury]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30230</uri>
			</author>
			<updated>2014-04-17T04:37:52Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=81863#p81863</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Найти файл, изменить и сохранить]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=81861#p81861" />
			<content type="html"><![CDATA[<p>спасибо, принцип понял<br />а искать сразу на всех существующих дисках невозможно ? т.е&nbsp; надо запускать еще один цикл с перебором&nbsp; дисков ?</p>]]></content>
			<author>
				<name><![CDATA[SNSheriff]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32108</uri>
			</author>
			<updated>2014-04-17T04:29:30Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=81861#p81861</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: Найти файл, изменить и сохранить]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=81854#p81854" />
			<content type="html"><![CDATA[<p>Будем выполнять все операции для диска &quot;<strong>C</strong>&quot; (для других дисков аналогично):</p><div class="codebox"><pre><code>@echo off
for /f &quot;delims=&quot; %%i in (&#039;dir &quot;C:\file.xml&quot; /a-d /b /s&#039;) do (
 echo %%i
 copy &quot;%%i&quot; &quot;%%~i.bak&quot;&gt;nul
 (
 for /f &quot;tokens=1* delims=:&quot; %%j in (&#039;findstr /n &quot;^&quot; &quot;%%i.bak&quot;&#039;) do (
  if &quot;%%k&quot;==&quot;12345=false&quot; (
   echo 12345=true
) else (
   echo:%%k
  )
 )
 )&gt;&quot;%%i&quot;
)
pause&gt;nul
exit /b</code></pre></div><p>.</p>]]></content>
			<author>
				<name><![CDATA[Yury]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30230</uri>
			</author>
			<updated>2014-04-16T18:14:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=81854#p81854</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[CMD/BAT: Найти файл, изменить и сохранить]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=81850#p81850" />
			<content type="html"><![CDATA[<p>дано:&nbsp; текстовый файл с именем file.xml,&nbsp; путь к нему неизвестен.<br />задача : <br />1.найти файл file.xml,<br />2.создать резервную копию file.xml.bak&nbsp; в том-же каталоге, <br />3.изменить в этом файле строку &quot;12345=false&quot; на &quot;12345=true&quot;<br />4.провести аналогичную операцию для всех найденных файлов</p>]]></content>
			<author>
				<name><![CDATA[SNSheriff]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=32108</uri>
			</author>
			<updated>2014-04-16T17:17:09Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=81850#p81850</id>
		</entry>
</feed>
