<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBS: удаление файлов по списку]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=6925&amp;type=atom" />
	<updated>2015-09-10T21:26:51Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=6925</id>
		<entry>
			<title type="html"><![CDATA[Re: VBS: удаление файлов по списку]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=97340#p97340" />
			<content type="html"><![CDATA[<p><strong>dmitriypopov86</strong><br />С копированием следовало бы обратиться в тему о копировании, а не удалении. Там же и опишите, что конкретно вы понимаете под рекурсивным копированием по списку (какому, куда и в каком виде).</p>]]></content>
			<author>
				<name><![CDATA[Flasher]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27593</uri>
			</author>
			<updated>2015-09-10T21:26:51Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=97340#p97340</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: удаление файлов по списку]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=97339#p97339" />
			<content type="html"><![CDATA[<p>Доброго времени суток! <br />Уважаемый Flasher, можно ли ваш скрипт переделать с другими параметрами?<br /></p><div class="quotebox"><cite>Flasher пишет:</cite><blockquote><p>Я бы так сделал:<br /></p><div class="codebox"><pre><code>&#039;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
&#039; Назначение: Рекурсивное удаление файлов в папках по списку имён
&#039; Параметры:
&#039; 1)          &quot;&lt;путь к списку обрабатываемых папок&gt;&quot;
&#039; 2)          &quot;&lt;путь к списку имён удаляемых файлов&gt;&quot;
&#039; 3)          &quot;&lt;путь к файлу отчёта&gt;&quot; (необязательный)

&#039; Автор:      Flasher ©
&#039;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••</code></pre></div></blockquote></div><p>Вместо 1го параметра, путь обрабатываемой папки и вместо удаления файлов , копирование по списку. Ваш скрипт очень актуален для моей работы , прошу помощи. Спасибо!</p>]]></content>
			<author>
				<name><![CDATA[dmitriypopov86]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=33344</uri>
			</author>
			<updated>2015-09-10T20:36:38Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=97339#p97339</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: удаление файлов по списку]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57912#p57912" />
			<content type="html"><![CDATA[<p>Я бы так сделал:<br /></p><div class="codebox"><pre><code>&#039;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
&#039; Назначение: Рекурсивное удаление файлов в папках по списку имён
&#039; Параметры:
&#039; 1)          &quot;&lt;путь к списку обрабатываемых папок&gt;&quot;
&#039; 2)          &quot;&lt;путь к списку имён удаляемых файлов&gt;&quot;
&#039; 3)          &quot;&lt;путь к файлу отчёта&gt;&quot; (необязательный)

&#039; Автор:      Flasher ©
&#039;••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

Title = &quot;   Рекурсивное удаление файлов&quot;
Set FSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)

&#039; Объявление и проверка наличия параметров
With WScript.Arguments
  If .Count &lt; 2 Then
    MsgBox  &quot;Укажите хотя бы 2 параметра!&quot;, 4144, Title : Quit
  End If : FoldList = .Item(0) : FileList = .Item(1)
  If .Count = 3 Then LogFile = .Item(2) : LF = 1 End If 
End With

&#039; Проверка наличия файлов-списков
Test(FoldList)(FileList)
Function Test(FF)
  If FF &lt;&gt; &quot;&quot; And Not FSO.FileExists(FF) Then
    MsgBox &quot;Файл &quot; &amp; FF &amp; &quot; отсутствует!&quot;, 4144, Space(10) &amp; Title : Quit
  End If : Set Test = GetRef(&quot;Test&quot;)
End Function

&#039; Проверка содержимого файлов-списков
Inside FoldList, Fd : Inside FileList, Fl
Sub Inside(FList, Spl)
 On Error Resume Next
   With FSO.OpenTextFile(FList) : L = .ReadLine : T = .ReadAll : End With
   If Err.Number = 0 Then
     Spl = Split(T, vbNewLine) : If Ubound(Spl) = 0 Then Msg FList
   ElseIf Trim(L) &lt;&gt; &quot;&quot; Then Spl = Array(L) Else Msg FList : End If
 On Error GoTo 0
End Sub
Sub Msg(FLs)
MsgBox &quot;Список &quot; &amp; FLs &amp; &quot; пуст!&quot;, 4144, Space(15) &amp; Title : Quit : End Sub

&#039; Создание коллекции из списка файлов
Set Dict = CreateObject(&quot;Scripting.Dictionary&quot;)
For Each F in Fl : Dict.Add Trim(F), &quot;&quot; : Next
If LF Then Set SpLog = FSO.OpenTextFile(LogFile, 8, True)

&#039; Проход по директориям из списка с выполнением процедуры удаления
For Each F in Fd
  F = Trim(F)
  If F &lt;&gt; &quot;&quot; Then
    If FSO.FolderExists(F) Then ForFolder FSO.GetFolder(F)  
  End If
Next : If LF Then SpLog.Close

&#039; Процедуры рекурсивного удаление файлов с именами из списка
Sub ForFolder(Folder)
  Dim N
  For Each N In Folder.SubFolders : ForFolder N : Next
  For Each N In Folder.Files      : ForFile   N : Next
End Sub
Sub ForFile(File)
  If Dict.Exists(FSO.GetFileName(File)) Then
    LogF = File : FSO.DeleteFile File, 0
    If LF And Not FSO.fileExists(LogF) Then _
    SpLog.WriteLine Now &amp; &quot; удалён файл &quot; &amp; LogF
  End If 
End Sub

&#039; Вывод всплывающего сообщения об окончании работы и выход
CreateObject(&quot;WScript.Shell&quot;).Popup &quot;Удаление файлов завершено!&quot;, 1.5,_
&quot;    &quot; &amp; Title, 64 : Quit
Sub Quit : Set FSO = Nothing : Set Dict = Nothing : WScript.Quit : End Sub</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Flasher]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27593</uri>
			</author>
			<updated>2012-03-16T11:35:46Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57912#p57912</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: удаление файлов по списку]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57809#p57809" />
			<content type="html"><![CDATA[<p>Не знаю, не пробовал Ваш код. Уберите «On Error Resume Next» и смотрите.</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2012-03-14T03:18:02Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57809#p57809</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: удаление файлов по списку]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57801#p57801" />
			<content type="html"><![CDATA[<p>хорошо, почему ж тогда при этом варианте в папке обработка идет, а в подпапках нет?</p>]]></content>
			<author>
				<name><![CDATA[griha09]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27540</uri>
			</author>
			<updated>2012-03-13T16:32:56Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57801#p57801</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: VBS: удаление файлов по списку]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57779#p57779" />
			<content type="html"><![CDATA[<p>Вы сначала удаляете файл, потом просите: «А скажи-ка, мил человек, каков твой путь?» А файла-то уже нет — Вы его удалили.</p><p>Можно так:<br /></p><div class="codebox"><pre><code>strPath = File.Path
objFSO.DeleteFile strPath, 1            &#039;удаляем
LogStream.WriteLine &quot;Был удален файл: &quot; &amp; strPath &amp; &quot;: &quot; &amp; Now()</code></pre></div>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2012-03-13T11:44:22Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57779#p57779</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[VBS: удаление файлов по списку]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=57778#p57778" />
			<content type="html"><![CDATA[<p>сделал простой скрипт по удалению файлов по списку. Вот так все работает<br /></p><div class="codebox"><pre><code>papka = &quot;c:\00000\&quot;
sps =&quot;c:\00000\456.txt&quot; &#039;файл со списком файлов

On Error Resume Next
Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
LogPath = objFSO.GetParentFolderName(WScript.ScriptFullName)
Set LogStream = objFSO.OpenTextFile(LogPath &amp; &quot;\DelLog.log&quot;, 8, True)
LogStream.WriteLine &quot;Начало удаления: &quot; &amp; Now()

&#039;читаем файл со списком файлов
Set File2 = objFSO.GetFile(sps)
Set TextStream = File2.OpenAsTextStream(1)
Str = vbNullString


While Not TextStream.AtEndOfStream
   Str = TextStream.ReadLine()

RecursiveFolderScan papka
Wend
LogStream.WriteLine &quot;Конец удаления: &quot; &amp; Now()
LogStream.WriteLine
LogStream.Close
TextStream.Close
Msgbox &quot;ВСЕ!&quot;


Sub RecursiveFolderScan(FolderPath)
    &#039;Получаем объектную модель текущего каталога
    Set Folder = objFSO.GetFolder(FolderPath)
 
    &#039;Перебираем все файлы в текущем каталоге
    For Each File in Folder.Files
         If LCase(File.Name)=LCase(Str) Then    &#039;и если имя файла совпадает со строкой из файла
                LogStream.WriteLine &quot;Был удален файл: &quot; &amp; File.Path &amp; &quot;: &quot; &amp; Now()
        objFSO.DeleteFile File.Path, 1            &#039;удаляем

    End if
    Next
 
    &#039;Перебираем все подкаталоги в каталоге
    For Each SubFolder in Folder.SubFolders
        RecursiveFolderScan(SubFolder.Path)
    Next
End Sub</code></pre></div><p>а если&nbsp; поменять местами строки<br /></p><div class="codebox"><pre><code>    objFSO.DeleteFile File.Path, 1            &#039;удаляем
          LogStream.WriteLine &quot;Был удален файл: &quot; &amp; File.Path &amp; &quot;: &quot; &amp; Now()</code></pre></div><p>начинает глючить. В подпапках не удаляет и в отчет не пишет. Почему? Такой порядок же логичнее?</p>]]></content>
			<author>
				<name><![CDATA[griha09]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=27540</uri>
			</author>
			<updated>2012-03-13T11:25:15Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=57778#p57778</id>
		</entry>
</feed>
