<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; JS: Удаление каталогов в зависимости от времени модификации]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=9986&amp;type=atom" />
	<updated>2014-09-20T12:39:15Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=9986</id>
		<entry>
			<title type="html"><![CDATA[Re: JS: Удаление каталогов в зависимости от времени модификации]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=86614#p86614" />
			<content type="html"><![CDATA[<p><strong>over4track</strong>, не Вы первый и, должно быть, не Вы последний... - пожалуйста, заключайте код в пару тэгов <strong>code</strong>, во-вторых, подобная тема как-то поднималась уже на форуме, но если ничего не найдете через поиск, то примерный вариант:<br /></p><div class="codebox"><pre><code>var fso = new ActiveXObject(&quot;Scripting.FileSystemObject&quot;);

with (WScript.Arguments.Named) {
  if (length != 2) {
    WScript.echo(WScript.ScriptName + &quot; /d:[path] /n:[days]&quot;);
    WScript.echo(&quot;  /d:[path] - a source folder&quot;);
    WScript.echo(&quot;  /n:[days] - days expired&quot;);
    WScript.Quit(1);
  }

  try {
    DeleteOlderThanX(Item(&quot;d&quot;), Item(&quot;n&quot;));
  }
  catch (e) {
    WScript.echo(e.message + &quot;.&quot;);
  }
}

function DateDiff(fileName) {
  var day = new Date(fso.GetFile(fileName).DateLastModified),
      now = new Date(), mil = 1 / (1000 * 60 * 60 * 24),
      res = (now - day) * mil;
  return(Math.floor(res));
}

function DeleteOlderThanX(dirName, dateExpire) {
  with (fso.GetFolder(dirName)) {
    var eFiles = new Enumerator(Files),
        eSubs = new Enumerator(Subfolders),
        itm;

    for (; !eFiles.atEnd(); eFiles.moveNext()) {
      itm = eFiles.item();

      if (DateDiff(itm) &gt; dateExpire) {
        WScript.echo(itm.Path + &quot;.....deleted.&quot;);
        itm.Attributes = 0;
        itm.Delete();
      }
    }

    for (; !eSubs.atEnd(); eSubs.moveNext()) {
      itm = eSubs.item();

      DeleteOlderThanX(itm.Path, dateExpire);
      WScript.echo(itm.Path + &quot;.....deleted.&quot;);
      if (itm.Size == 0) {
        itm.Attributes = 0;
        itm.Delete();
      }
    }
  }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[greg zakharov]]></name>
			</author>
			<updated>2014-09-20T12:39:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=86614#p86614</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[JS: Удаление каталогов в зависимости от времени модификации]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=86612#p86612" />
			<content type="html"><![CDATA[<p>Помогите реализовать код для удаление каталогов в зависимости от времени модификации</p>]]></content>
			<author>
				<name><![CDATA[over4track]]></name>
			</author>
			<updated>2014-09-20T12:10:03Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=86612#p86612</id>
		</entry>
</feed>
