<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; CMD/BAT: присвоение файлу .txt имя согласно его тексту]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=8305&amp;type=atom" />
	<updated>2013-05-16T17:07:45Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=8305</id>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: присвоение файлу .txt имя согласно его тексту]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=72178#p72178" />
			<content type="html"><![CDATA[<p>присвойте переменную самой себе</p>]]></content>
			<author>
				<name><![CDATA[smaharbA]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2911</uri>
			</author>
			<updated>2013-05-16T17:07:45Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=72178#p72178</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: присвоение файлу .txt имя согласно его тексту]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=72126#p72126" />
			<content type="html"><![CDATA[<p>Решено:<br /></p><div class="codebox"><pre><code>
:m1
for /f &quot;usebackq tokens=1 delims=&quot; %%a in (`findstr.exe /r /s /b /c:&quot;от .* года&quot; &quot;C:\Downloads\!!!\*.txt&quot;`) do set name=%%a   &lt;-- отправляем строку из файла в переменную %%name
for /f &quot;usebackq tokens=1-2,3 delims=:&quot; %%a in (&#039;%name%&#039;) do set name1=%%c   &lt;--  делим строку из переменной %%name на части и берем ту что с датой и номером. Отправляем эту часть в переменную %%name1
for /f &quot;usebackq tokens=1-2,3 delims=:&quot; %%a in (&#039;%name%&#039;) do set name2=%%a:%%b   &lt;--  делим строку из переменной %%name на части и берем ту что содержит путь к файлу. Отправляем эту часть в переменную %%name2
for /f &quot;usebackq tokens=1-8* delims= &quot; %%i in (&#039;%name1%&#039;) do set name3=%%i %%j %%k %%l %%m %%n %%o   &lt;--  удаляем лишние пробелы и отправляем  в переменную %%name3
find &quot;от&quot; &quot;%name2%&quot; 
if %errorlevel%==0 goto m2
goto m3
:m2
ren &quot;%name2%&quot; &quot;%name1%.doc&quot; &lt;--  переименовываем файл согласно пути из переменной %%name2 на название согласно переменной %%name2 и меняем формат для избежания повторной обработки!
goto m1
:m3
exit
</code></pre></div><p>+ еще 1 батник запускаться будет по окончании работы дабы вернуть формат .txt</p>]]></content>
			<author>
				<name><![CDATA[Nikro90]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30125</uri>
			</author>
			<updated>2013-05-15T06:14:31Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=72126#p72126</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: присвоение файлу .txt имя согласно его тексту]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=72125#p72125" />
			<content type="html"><![CDATA[<div class="quotebox"><cite>alexii пишет:</cite><blockquote><p>Как-то так:<br /></p><div class="codebox"><pre><code>@echo off
setlocal enableextensions enabledelayedexpansion

for /f &quot;usebackq tokens=1-2,4-7,9 delims=: &quot; %%i in (
    `findstr.exe /r /s /c:&quot;^от .* года *№ [0-9]*$&quot; &quot;C:\Песочница\011\*.txt&quot;`
) do ren &quot;%%i:%%j&quot; &quot;%%k %%l %%m %%n № %%o.txt&quot;

endlocal
exit /b 0
</code></pre></div></blockquote></div><p>Почти, в пути к файлам есть пробелы и кодировка сбоит немного.<br />+ пути разные, папки бывают с двойным вложением, а некоторые файлы в основной папке лежат, а не в корне</p><div class="codebox"><pre><code>
@echo off
setlocal enableextensions enabledelayedexpansion

for /f &quot;usebackq tokens=1-2,4-7,9 delims=: &quot; %%i in (
    `findstr.exe /r /s /b /c:&quot;^от .* года  *№ [0-9]*$&quot; &quot;C:\Downloads\!!!\*.txt&quot;`
) do ren &quot;%%i:%%j&quot; &quot;%%k %%l %%m %%n № %%o.txt&quot;

endlocal
exit /b 0
</code></pre></div><p>но из за пробелов в пути к файлу или в его начальном названии получаем это:</p><div class="codebox"><pre><code>

C:\Downloads\!!!&gt;setlocal enableextensions enabledelayedexpansion 

C:\Downloads\!!!&gt;for /F &quot;usebackq tokens=1-2,4-7,9 delims=: &quot; %i in (`findstr.exe /r /s /b /c:&quot;^от .* года *№ [0-9]*$&quot; &quot;C:\Downloads\!!!\*.txt&quot;`) do ren &quot;%i:%j&quot; &quot;%k %l %m %n № %o.txt&quot; 

C:\Downloads\!!!&gt;ren &quot;C:\Downloads\\!!!\r20120215_101\№&quot; &quot;от 15 февраля 2012 № №.txt&quot; 

C:\Downloads\!!!&gt;ren &quot;C:\Downloads\\!!!\r20120215_107\№&quot; &quot;от 25 января 2012 № №.txt&quot; 

C:\Downloads\!!!&gt;ren &quot;C:\Downloads\\!!!\Новая&quot; &quot;103.txt от 15 февраля № года.txt&quot; 

C:\Downloads\!!!&gt;ren &quot;C:\Downloads\\!!!\Новая&quot; &quot;104.txt от 15 февраля № года.txt&quot; 

C:\Downloads\!!!&gt;ren &quot;C:\Downloads\\!!!\№&quot; &quot;от 15 февраля 2012 № №.txt&quot; 

C:\Downloads\!!!&gt;ren &quot;C:\Downloads\\!!!\№&quot; &quot;от 15 марта 2012 № №.txt&quot; 

C:\Downloads\!!!&gt;endlocal

C:\Downloads\!!!&gt;exit /b 0 
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Nikro90]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30125</uri>
			</author>
			<updated>2013-05-15T02:29:11Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=72125#p72125</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: CMD/BAT: присвоение файлу .txt имя согласно его тексту]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=72105#p72105" />
			<content type="html"><![CDATA[<p>Как-то так:<br /></p><div class="codebox"><pre><code>@echo off
setlocal enableextensions enabledelayedexpansion

for /f &quot;usebackq tokens=1-2,4-7,9 delims=: &quot; %%i in (
    `findstr.exe /r /s /c:&quot;^от .* года *№ [0-9]*$&quot; &quot;C:\Песочница\011\*.txt&quot;`
) do ren &quot;%%i:%%j&quot; &quot;%%k %%l %%m %%n № %%o.txt&quot;

endlocal
exit /b 0
</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2013-05-14T11:47:32Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=72105#p72105</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[CMD/BAT: присвоение файлу .txt имя согласно его тексту]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=72100#p72100" />
			<content type="html"><![CDATA[<p>Задача такая: есть куча папок с документами в .txt формате, нужно их (документы) переименовать согласно дате и номеру написанному внутри самого документа. <br />Найти строки с датой и номером не составило труда:<br /></p><div class="codebox"><pre><code>
for /f  &quot;delims=&quot; %b in (&#039;findstr /r /s /B &quot;от&quot; C:\Downloads\!!!\*.doc&#039;) do Set name=%b
</code></pre></div><p>Пример формата даты и номера:</p><p>от 15 февраля 2012 года&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;№ 104</p><p>Проблема в том, что строка вместе с путем файла выходит, а между датой и номером куча пробелов! Как бы это убрать? Нужно чисто дату и номер.<br />Подскажите кто может.</p>]]></content>
			<author>
				<name><![CDATA[Nikro90]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=30125</uri>
			</author>
			<updated>2013-05-14T09:09:08Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=72100#p72100</id>
		</entry>
</feed>
