Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8088

Профиль | Отправить PM | Цитировать


Пусть будет и на WSH:
Скрытый текст
Код: Выделить весь код
Option Explicit

Dim strSourceFolder
Dim strPatternFile

Dim objFSO
Dim objFile

Dim objDictionary

Dim strLine
Dim arrParts

Dim strKey
Dim strDestFolder


strSourceFolder = "C:\Мои проекты\0040\sso"
strPatternFile  = "C:\Мои проекты\0040\sso\raz.txt"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

If objFSO.FolderExists(strSourceFolder) Then
	If objFSO.FileExists(strPatternFile) Then
		Set objDictionary = WScript.CreateObject("Scripting.Dictionary")
		
		With objFSO.OpenTextFile(strPatternFile)
			Do Until .AtEndOfStream
				strLine = Trim(.ReadLine())
				
				If InStr(strLine, "#") > 0 Then
					arrParts = Split(strLine, "#")
					
					If Not objDictionary.Exists(arrParts(0)) Then
						objDictionary.Add arrParts(0), arrParts(1)
					Else
						objDictionary.Item(arrParts(0)) = arrParts(1)
					End If
				End If
			Loop
			
			.Close
		End With
		
		For Each objFile In objFSO.GetFolder(strSourceFolder).Files
			If StrComp(objFSO.GetExtensionName(objFile.Name), "xml", vbTextCompare) = 0 Then
				WScript.Echo objFile.Name
				
				With WScript.CreateObject("Microsoft.XMLDOM")
					.load(objFile.Path)
					strKey = .selectSingleNode("/report/title/item[@name='okpo']").GetAttribute("value")
				End With
				
				If objDictionary.Exists(strKey) Then
					strDestFolder = objDictionary.Item(strKey)
					
					If Not objFSO.FolderExists(strDestFolder) Then
						objFSO.CreateFolder strDestFolder
					End If
					
					If Not objFSO.FileExists(objFSO.BuildPath(strDestFolder, objFile.Name)) Then
						WScript.Echo vbTab, "Move into [" & strDestFolder & "\]"
						objFile.Move strDestFolder & "\"
					Else
						WScript.Echo vbTab, "Can't move: destination file [" & objFSO.BuildPath(strDestFolder, objFile.Name) & "] already exists."
					End If
				End If
			End If
		Next
		
		objDictionary.RemoveAll
		Set objDictionary = Nothing
	Else
		WScript.Echo "Can't find pattern file [" & strPatternFile & "]."
		WScript.Quit 2
	End If
Else
	WScript.Echo "Can't find source folder [" & strSourceFolder & "]."
	WScript.Quit 1
End If

Set objFSO = Nothing

WScript.Quit 0

Отправлено: 06:41, 04-02-2017 | #9