<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; CMD/BAT: Получить расширение файла из переменной]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=6605</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=6605&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «CMD/BAT: Получить расширение файла из переменной».]]></description>
		<lastBuildDate>Tue, 27 Dec 2011 12:40:15 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55023#p55023</link>
			<description><![CDATA[<p>Да да, пробел нужен. Мне так удобней. А пустых имен нету, потому как, в ручном режиме все проверяю.<br />Книжки электронные решил, к одному виду привести. А то все как попало, разными архиваторами упакованные, названия, авторы, рус/анл...<br />Так что в таком виде код вполне устраивает. Отрабатывает без глюков. Спс.</p><p>То есть Привожу к виду:</p><p>Учение дона Хуана.txt<br />Путешествие в Икстлан.rtf</p><p>Переконвертить в</p><p>Учение дона Хуана [txt].7z<br />Путешествие в Икстлан [rtf].7z</p><p>и тд...</p>]]></description>
			<author><![CDATA[null@example.com (DnsIs)]]></author>
			<pubDate>Tue, 27 Dec 2011 12:40:15 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55023#p55023</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55016#p55016</link>
			<description><![CDATA[<p>То есть Вам надо получить не просто <strong>filename.ext.7z</strong>, а именно <strong>filename[ext].7z</strong>. Полагаю, что в строке </p><div class="codebox"><pre><code>str= [!ext:~1!]</code></pre></div><p>опечатка и пробела после знака равенства быть не должно. Или Вам нужен именно такой результат <strong>filename [ext].7z</strong>? В таком случае существует небольшая вероятность получить файл с ведущим пробелом в начале имени файла, если исходный файл будет без имени, например <strong>.ext</strong>.</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Tue, 27 Dec 2011 10:03:24 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55016#p55016</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55015#p55015</link>
			<description><![CDATA[<p>Спс за дополнение.</p><p>Суть батника была такая (с учетом ваших дополнений):<br /></p><div class="codebox"><pre><code>@setlocal enabledelayedexpansion
@for /f &quot;tokens=*&quot; %%a in (&#039;dir *.* /b&#039;) do @(
    set ext=%%~xa
    set str=
    if defined ext set str= [!ext:~1!]
    &quot;c:\Program Files\7-Zip\7z.exe&quot; a -r -t7z &quot;%%~na!str!.7z&quot; &quot;%%a&quot;
)</code></pre></div><p>Жать все файлы и папки в текущей директории, добавляя расширение в имя архива.</p>]]></description>
			<author><![CDATA[null@example.com (DnsIs)]]></author>
			<pubDate>Tue, 27 Dec 2011 09:32:12 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55015#p55015</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55013#p55013</link>
			<description><![CDATA[<p>А вот еще один баг. Создайте файл <em>без расширения</em>. Запустите скрипт. Посмотрите результат. </p><p>Лечится так:<br /></p><div class="codebox"><pre><code>if defined ext echo !ext:~1!</code></pre></div><p>Это не проблема расширения. Это проблема интерпретатора командной строки - раскрытие значения несуществующей переменной.</p>]]></description>
			<author><![CDATA[null@example.com (Rumata)]]></author>
			<pubDate>Tue, 27 Dec 2011 08:22:11 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55013#p55013</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55011#p55011</link>
			<description><![CDATA[<p>Ура все получилось.<br /></p><div class="codebox"><pre><code>@setlocal enabledelayedexpansion
@for /f &quot;tokens=*&quot; %%a in (&#039;dir *.* /b&#039;) do @(
    set ext=%%~xa
    echo !ext:~1!
)</code></pre></div><p>Спасибо всем, кто принял участие в теме.</p>]]></description>
			<author><![CDATA[null@example.com (DnsIs)]]></author>
			<pubDate>Tue, 27 Dec 2011 08:06:39 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55011#p55011</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55010#p55010</link>
			<description><![CDATA[<p>Сообразил код.<br /></p><div class="codebox"><pre><code>@for /f &quot;tokens=*&quot; %%a in (&#039;dir *.* /b&#039;) do @(
    set ext=%%~xa
    echo !ext:~1!</code></pre></div><p>Но работает только если запустить cmd.exe /v</p><p>Если же просто запустить батник, то код не отрабатывает. Тоска печаль.</p>]]></description>
			<author><![CDATA[null@example.com (DnsIs)]]></author>
			<pubDate>Tue, 27 Dec 2011 07:59:53 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55010#p55010</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55009#p55009</link>
			<description><![CDATA[<p>Прочел внимательней set /?, ошибку свою понял. Но пока не понимаю как правильно написать код.</p>]]></description>
			<author><![CDATA[null@example.com (DnsIs)]]></author>
			<pubDate>Tue, 27 Dec 2011 07:55:24 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55009#p55009</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55007#p55007</link>
			<description><![CDATA[<p>Еще вопросец в продолжении темы. Совсем не догоняю почему так.</p><p>Есть папка в которой лежит 2 файла.</p><p>set.txt<br />script.cmd<br /></p><div class="codebox"><pre><code>@for /f &quot;tokens=*&quot; %%a in (&#039;dir *.* /b&#039;) do @(
    set ext=%%~xa
    echo %ext:~1%
)</code></pre></div><p>Во лог команд консоли:</p><div class="codebox"><pre><code>c:\tmp&gt;script.cmd
~1
~1

c:\tmp&gt;script.cmd
txt
txt

c:\tmp&gt;ren set.txt set.log

c:\tmp&gt;script.cmd
txt
txt

c:\tmp&gt;script.cmd
log
log</code></pre></div><p>Вопросы. возникли.<br />Почему при первом запуске получается ~1?<br />Почему выводится расширение только txt файла?<br />Почему после переименования, батник только со 2 раза начинает догадываться, что-то тут не так?</p><p>Кажется мне почему то что я глупости пишу тут. Но прошу, если не охота объяснять, хотя бы ткните в правильную страницу мануала.</p>]]></description>
			<author><![CDATA[null@example.com (DnsIs)]]></author>
			<pubDate>Tue, 27 Dec 2011 07:44:16 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55007#p55007</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55005#p55005</link>
			<description><![CDATA[<p>Благодарю.</p>]]></description>
			<author><![CDATA[null@example.com (DnsIs)]]></author>
			<pubDate>Tue, 27 Dec 2011 07:24:46 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55005#p55005</guid>
		</item>
		<item>
			<title><![CDATA[Re: CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55004#p55004</link>
			<description><![CDATA[<div class="codebox"><pre><code>set ext=%~x0
echo %ext:*.=%

echo %ext:~1%</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (smaharbA)]]></author>
			<pubDate>Tue, 27 Dec 2011 07:22:14 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55004#p55004</guid>
		</item>
		<item>
			<title><![CDATA[CMD/BAT: Получить расширение файла из переменной]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=55003#p55003</link>
			<description><![CDATA[<p>С наступающим всех. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p><p>Голова под конец года не хочет работать. Проблема такая.</p><p>code.cmd<br /></p><div class="codebox"><pre><code>@echo %~x0</code></pre></div><p>Выводит расширение с точкой:<br />.cmd</p><p>Как получить без точки?</p><p>Заранее благодарю.</p>]]></description>
			<author><![CDATA[null@example.com (DnsIs)]]></author>
			<pubDate>Tue, 27 Dec 2011 07:14:23 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=55003#p55003</guid>
		</item>
	</channel>
</rss>
