Total Commander Forum Index Total Commander
Форум поддержки пользователей Total Commander
Сайты: Все о Total Commander | Totalcmd.net | Ghisler.com | RU.TCKB
 
 RulesRules   SearchSearch   FAQFAQ   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Single Post  Topic: Надо найти 40 файлов и удалить! 
Author Message
Batya



PostPosted: Mon May 04, 2009 13:13    Post subject: Reply with quote

gegabit wrote:
Ну если возможно сформировать по результатам проверки отсутствующие файлы в отдельном файл-списке, было бы замечательно!
Code:
'=========================================================================
' Проверка существования файлов\папок, представленных в файле-списке.
' Результат действия скрипта - формируемся итоговый файл-список
'   с отсутствующими файлами\папками
'
' Параметры:
' {исходный файл-список} {итоговый файл-список}
'
' Автор - Batya
'=========================================================================
Option Explicit
'======== Изменяемые параметры ===========================================
Const FolderCheck = True  'Проверять ли папки
Const FileCheck   = True  'Проверять ли файлы
Const Existing    = False 'Что помещать в итоговый файл
'=========================================================================
Dim Mess, FSO, WSH, FF1, FF2, F, TFL, List
SetMess
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSH = CreateObject("WScript.Shell")
CheckParam

For Each F In Split(FSO.OpenTextFile(FF1).ReadAll, vbNewLine)
  If F <> "" Then
    F = GetPath(F)
    If ExistsCheck(F) Then List = List & vbNewLine & F
  End If
Next
If List <> "" Then List = Mid(List, Len(vbNewLine) + 1)
On Error Resume Next
Set TFL = FSO.CreateTextFile(FF2, True)
If Err.Number <> 0 Then
  MessBox Mess(5) & vbNewLine & Err.Description, 1
  Err.Clear
  Quit
End If
TFL.Write List
If Err.Number <> 0 Then
  MessBox Mess(5) & vbNewLine & Err.Description, 1
  Err.Clear
  Quit
End If
On Error GoTo 0

MessBox Mess(4), 3
Quit

Sub SetMess
  Set Mess = CreateObject("Scripting.Dictionary")
  With Mess
    .Add 0,  "Проверка существования файлов\папок"
    .Add 1,  "Не указаны параметры!"
    .Add 2,  "Первый параметр не является файлом-списком!"
    .Add 3,  "Не указан итоговый файл-список!"
    .Add 4,  "Операция завершена."
    .Add 5,  "Операция прервана по причине ошибки:"
  End With
End Sub

Sub CheckParam
  If WScript.Arguments.Count = 0 Then
    MessBox Mess(1), 1
    Quit
  End If
  FF1 = GetPath(WScript.Arguments(0))
  If Not FSO.FileExists(FF1) Then
    MessBox Mess(2), 1
    Quit
  End If
  If WScript.Arguments.Count = 1 Then
    MessBox Mess(3), 1
    Quit
  End If
  FF2 = GetPath(WScript.Arguments(1))
End Sub

Function GetPath(pPath)
  GetPath = FSO.GetAbsolutePathName(WSH.ExpandEnvironmentStrings(pPath))
End Function

Function ExistsCheck(pPath)
  If FolderCheck And (Not FSO.FileExists(pPath)) And (Not (Existing Xor FSO.FolderExists(pPath))) Then
    ExistsCheck = True
    Exit Function
  End If
  If FileCheck And (Not FSO.FolderExists(pPath)) And (Not (Existing Xor FSO.FileExists(pPath))) Then
    ExistsCheck = True
    Exit Function
  End If
  ExistsCheck = False
End Function

Function MessBox(pMess, pMode)
  Dim lIcon
  Select Case pMode
    Case 1 lIcon = vbCritical    + vbOKOnly
    Case 2 lIcon = vbExclamation + vbOKOnly
    Case 3 lIcon = vbInformation + vbOKOnly
  End Select
  MessBox = MsgBox(pMess, lIcon, Mess(0))
End Function

Sub Quit
  Set Mess = Nothing
  Set WSH  = Nothing
  Set TFL  = Nothing
  Set FSO  = Nothing
  WScript.Quit
End Sub

_________________
Нет, я не сплю. Я просто медленно моргаю.


Last edited by Batya on Fri May 08, 2009 15:33; edited 1 time in total
View user's profile Send private message


Powered by phpBB © 2001, 2005 phpBB Group