Question : Script to extract information from xml and move files

Hi All

I'm hopping some one can help me with this.
I'm looking for a script that can be run from any windows pc that can extract the "graphics id" in an xml file and then copy all the files with the names of the graphic id from one directory into another directory. Once all the files have been copied it must make sure all the files exist in the destination directory before deleting them from the first directory. At times the graphic might not exists in the source directory but will exist in the destination directory or if the graphic is missing compleatly it must email me with the missing id.

I've attached an example xml file.  

Many thanks in advance
Attachments:
 
example XML
 

Answer : Script to extract information from xml and move files

TazEE,

I will see what I can do to assist.  You posted sample xml file is an invalid xml file as it is missing several closing tags.  I have tried to adjust and work with it.  Below is an adjusted script that should help you along your way.  I have tried to put some comments in to assist.

For you immediate issues of more than one graphic, you need to loop through the Node List that you get.  Right now you are only grabbing the first one found.  Also, I suggest you check to make sure it has a graphic ID as your sample had some AD nodes without a graphic ID.  Let me know if you have questions as you work through the script.

Instead of writing out to a file I just kept all the graphic IDs in a string array in memory (strGraphicList)

-Bear
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
Dim fso, outfile, Graphic, Elem
Dim strFromDir, strToDir, strGraphicList(), i
Set fso = CreateObject("Scripting.FileSystemObject")

' **** Set your Directory Values Here ****
strFromDir = "C:\Original"
strToDir = "C:\New"
i = 0

Set xmlDoc = CreateObject("Msxml2.DOMDocument")
xmlDoc.load("C:\test\test.XML")

Set ElemList = xmlDoc.getElementsByTagName("Ad")

' ElemList.Length will show you how many AD nodes you found
' msgbox ElemList.Length

' Loop Through your Node List
For Each Elem in ElemList

	' Check to see if this Node has an Attribute Named Graphic
	If not Elem.getAttribute("Graphic") Then
		' Make sure the Array is the right Size
		Redim Preserve strGraphicList(i)
		
		' If so, assign the attributes value to an Array
		strGraphicList(i) = Elem.getAttribute("Graphic")
		
		' Increment the counter
		i = i + 1
	End If
Next


' Loop Through the Array
For i = 0 to Ubound(strGraphicList) - 1
	' Make sure the original File Exists in the Source
	If fso.FileExists(sstrFromDir & "\" & strGraphicList(i)) Then
		' Found the File - Copy to Destination
		fso.CopyFile strFromDir & "\" & strGraphicList(i), strToDir & "\"
	End If
Next
		
' Validate that All Files exit in Destination
For i = 0 to Ubound(strGraphicList) - 1
	' Make sure the original File Exists in the Source
	If NOT fso.FileExists(strToDir & "\" & strGraphicList(i)) Then
		' Found NOT Found
		msgbox "Graphic ID " & strGraphicList(i) & "was not found"
	End If
Next
		
msgbox "Done"
Random Solutions  
 
programming4us programming4us