<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Сохранение древовидной структуры]]></title>
		<link>https://forum.script-coding.com/viewtopic.php?id=15032</link>
		<atom:link href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=15032&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Сохранение древовидной структуры».]]></description>
		<lastBuildDate>Tue, 29 Oct 2019 21:26:44 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Сохранение древовидной структуры]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=136494#p136494</link>
			<description><![CDATA[<div class="codebox"><pre><code>MsgBox, % xmlDoc.xml</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Tue, 29 Oct 2019 21:26:44 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=136494#p136494</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Сохранение древовидной структуры]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=136491#p136491</link>
			<description><![CDATA[<p>Как можно получить содержимое xml-файла в переменную? То есть вместо сохранения в файл всё то же самое передать в переменную?</p>]]></description>
			<author><![CDATA[null@example.com (ypppu)]]></author>
			<pubDate>Tue, 29 Oct 2019 19:11:17 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=136491#p136491</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Сохранение древовидной структуры]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=136448#p136448</link>
			<description><![CDATA[<p>Нашёл, как отформатировать сразу:<br /></p><div class="codebox"><pre><code>#NoEnv
SetBatchLines, -1

CreateXmlFromFolder(&quot;D:\Downloads&quot;)

CreateXmlFromFolder(folder) {
   xmlDoc := ComObjCreate(&quot;Msxml2.DOMDocument.6.0&quot;)
   xmlDoc.async := false
   SplitPath, folder, fileName
   xmlDoc.loadXML(&quot;&lt;folder name=&quot;&quot;&quot; . fileName . &quot;&quot;&quot;&gt;&lt;/folder&gt;&quot;)
   root := xmlDoc.documentElement
   Parse(xmlDoc, folder, root)
   FormatDocument(xmlDoc)
   xmlDoc.save(A_ScriptDir . &quot;\test.xml&quot;)
}

Parse(xmlDoc, folder, node) {
   Loop, files, %folder%\*, D
   {
      newElem := xmlDoc.createElement(&quot;folder&quot;)
      newNode := node.appendChild(newElem)
      newNode.setAttribute(&quot;name&quot;, A_LoopFileName)
      Parse(xmlDoc, A_LoopFilePath, newNode)
   }
   Loop, files, %folder%\*, F
   {
      newElem := xmlDoc.createElement(&quot;file&quot;)
      newNode := node.appendChild(newElem)
      newNode.setAttribute(&quot;name&quot;, A_LoopFileName)
   }
}

FormatDocument(xmlDoc) {
   xmlReader := ComObjCreate(&quot;msxml2.SAXXMLReader.6.0&quot;)
   xmlWriter := ComObjCreate(&quot;msxml2.MXXMLWriter.6.0&quot;)
   xmlWriter.encoding := &quot;UTF-8&quot;
   xmlWriter.byteOrderMark := true
   xmlWriter.disableOutputEscaping := false
   xmlWriter.omitXMLDeclaration := false
   xmlWriter.indent := true
   xmlReader.contentHandler  := xmlWriter
   xmlReader.dtdHandler      := xmlWriter
   xmlReader.errorHandler    := xmlWriter
   xmlReader.putProperty(&quot;http://xml.org/sax/properties/lexical-handler&quot;, xmlWriter)
   xmlReader.putProperty(&quot;http://xml.org/sax/properties/declaration-handler&quot;, xmlWriter)
   xmlReader.parse(xmlDoc)
   xmlDoc.loadXML(xmlWriter.output)
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Fri, 25 Oct 2019 00:22:30 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=136448#p136448</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Сохранение древовидной структуры]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=136447#p136447</link>
			<description><![CDATA[<p>Есть такое понятие, как рекурсивный обход. Пример создания XML из дерева папок:<br /></p><div class="codebox"><pre><code>#NoEnv
SetBatchLines, -1

CreateXmlFromFolder(&quot;D:\Downloads&quot;)

CreateXmlFromFolder(folder) {
   xmlDoc := ComObjCreate(&quot;Msxml2.DOMDocument.3.0&quot;)
   xmlDoc.async := false
   SplitPath, folder, fileName
   xmlDoc.loadXML(&quot;&lt;folder name=&quot;&quot;&quot; . fileName . &quot;&quot;&quot;&gt;&lt;/folder&gt;&quot;)
   root := xmlDoc.documentElement
   Parse(xmlDoc, folder, root)
   xmlDoc.save(A_ScriptDir . &quot;\test.xml&quot;)
}

Parse(xmlDoc, folder, node) {
   Loop, files, %folder%\*, D
   {
      newElem := xmlDoc.createElement(&quot;folder&quot;)
      node.appendChild(newElem)
      node.lastChild.setAttribute(&quot;name&quot;, A_LoopFileName)
      Parse(xmlDoc, A_LoopFilePath, node.lastChild)
   }
   Loop, files, %folder%\*, F
   {
      newElem := xmlDoc.createElement(&quot;file&quot;)
      node.appendChild(newElem)
      node.lastChild.setAttribute(&quot;name&quot;, A_LoopFileName)
   }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Thu, 24 Oct 2019 19:21:37 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=136447#p136447</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Сохранение древовидной структуры]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=136446#p136446</link>
			<description><![CDATA[<p>Ясно, спасибо.<br />А как лучше парсить? Можно перебирать все файлы и папки от начала до конца, но не понятно как дать понять скрипту, какая папка (либо файл) в какую папку вложена?<br />Можно брать по порядку папки, расположенные внутри коревой папки, прочёсывать все подпапки и файлы. Надо будет как-то запоминать, в которой папке сейчас &quot;находится&quot; скрипт и какие папки уже были просмотрены. Что-то сложно получается.</p>]]></description>
			<author><![CDATA[null@example.com (ypppu)]]></author>
			<pubDate>Thu, 24 Oct 2019 18:32:02 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=136446#p136446</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Сохранение древовидной структуры]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=136445#p136445</link>
			<description><![CDATA[<p>Собственно, и сам XML-файл может понадобиться только для того, чтобы сохранять предыдущие состояния файловой системы. Чтобы получать текущую информацию, проще сразу парсить саму файловую систему.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Thu, 24 Oct 2019 17:54:55 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=136445#p136445</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Сохранение древовидной структуры]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=136444#p136444</link>
			<description><![CDATA[<div class="quotebox"><cite>ypppu пишет:</cite><blockquote><p>Как из объекта сохранить в файл, я вроде придумал.</p></blockquote></div><p>По-моему, объект здесь лишнее звено, если имеешь в виду объект {}. Рекурсивным обходом папок можно создать XML-файл, потом, если нужно получать информацию из этого файла, загружаем этот файл и работаем с объектом Xml Document. Его можно рекурсивно парсить.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Thu, 24 Oct 2019 17:40:44 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=136444#p136444</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Сохранение древовидной структуры]]></title>
			<link>https://forum.script-coding.com/viewtopic.php?pid=136443#p136443</link>
			<description><![CDATA[<p>На жёстком диске имеется папка, которая может содержать файлы, другие подпапки, те в свою очередь могут также хранить внутри себя файлы и подпапки и т. д. В общем, разветвлённая структура с большой степенью вложенности.</p><p>Хочется всё это дело пропарсить и иметь возможность держать в переменной (точнее в объекте), и сохранять в&nbsp; xml-файл (в xml нажал плюсик - раскрывается ветка дерева).</p><p>Как из объекта сохранить в файл, я вроде придумал. Трудности возникли с тем, как сохранять в объект.<br /></p><div class="codebox"><pre><code>Root := {}

%A_LoopFile% := &quot;Мои документы\Моя музыка\классика\Укупник.mp3&quot;
Root[&quot;Мои документы&quot;, &quot;Моя музыка&quot;, &quot;классика&quot;] := %A_LoopFile%

%A_LoopFile% := &quot;Мои документы\Моя музыка\попса\кантри\Газманов.wav&quot;
Root[&quot;Мои документы&quot;, &quot;Моя музыка&quot;, &quot;попса&quot;, &quot;кантри&quot;] := %A_LoopFile%</code></pre></div><p>Сколько будет уровней, заранее неизвестно, поэтому сделать шаблон не удаётся. Какие есть идеи?</p>]]></description>
			<author><![CDATA[null@example.com (ypppu)]]></author>
			<pubDate>Thu, 24 Oct 2019 14:55:47 +0000</pubDate>
			<guid>https://forum.script-coding.com/viewtopic.php?pid=136443#p136443</guid>
		</item>
	</channel>
</rss>
