Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.
C:\>notepad filename
Find xml / pdf file name. Assign to variable. (need to know what filename to open based on date etc?).Find in filename.xml the actual name (need to know how to distinguish this).Use actual name as the name to copy the filename.pdf to D:\
Option ExplicitDim objFSO,objFile,line,strToFindDim myFiles, srcFolder, dstFileDim pdfBase,xmlBase,iSet objFSO = CreateObject("Scripting.FileSystemObject")srcFolder="c:\temp" 'Server locationstrToFind = "Rep1_test" 'Enter string you want to find'dstFile = "c:\temp\"&strToFind 'this is file to rename toDim pdfStore(),pdfFullStore()i=0For Each myFiles In objFSO.GetFolder(srcFolder).Files If objFSO.GetExtensionName(myFiles) = "pdf" Then pdfBase = objFSO.GetBaseName(myFiles) ReDim Preserve pdfStore(i) ReDim Preserve pdfFullStore(i) pdfStore(i)=pdfBase pdfFullStore(i)=myFiles i=i+1 End If NextFor Each myFiles In objFSO.GetFolder(srcFolder).Files If objFSO.GetExtensionName(myFiles) = "xml" Then xmlBase = objFSO.GetBaseName(myFiles) For i=LBound(pdfStore) To UBound(pdfStore) If pdfStore(i) = xmlBase Then WScript.Echo "found " , xmlBase, pdfStore(i) Set objFile=objFSO.OpenTextFile(myFiles,1) Do Until objFile.AtEndOfLine line=objFile.ReadLine If InStr(1, line, strToFind) >0 Then WScript.Echo "found repl_test ", line WScript.Echo "Renaming pdf ..." objFSO.MoveFile pdfFullStore(i),dstFile&".pdf" End If Loop Set objFile=Nothing End If Next End If Next
strToFind = "Rep1_test" 'Enter string you want to find'dstFile = "c:\temp\"&strToFind 'this is file to rename to
If that doesn't work and / or you'd like a 100% automated batch script I STILL would need to know "How to decide what .xml / .pdf file to perform the actions on, is it based on last modified etc. or would it just be the only one in the folder?".ghostdog74's code, I believe requires manual input each time, as I believe the actual report name in the xml file would change.QuotestrToFind = "Rep1_test" 'Enter string you want to find'dstFile = "c:\temp\"&strToFind 'this is file to rename toIf I'm correct this means you have to know what you're looking for to find it, I believe you would like that process to be automated.Please answer the questions and I'm sure ghostdog will also improve his script if indeed that is required?
Quote from: DeltaSlaya on August 16, 2007, 04:41:03 AMIf that doesn't work and / or you'd like a 100% automated batch script I STILL would need to know "How to decide what .xml / .pdf file to perform the actions on, is it based on last modified etc. or would it just be the only one in the folder?".ghostdog74's code, I believe requires manual input each time, as I believe the actual report name in the xml file would change.QuotestrToFind = "Rep1_test" 'Enter string you want to find'dstFile = "c:\temp\"&strToFind 'this is file to rename toIf I'm correct this means you have to know what you're looking for to find it, I believe you would like that process to be automated.Please answer the questions and I'm sure ghostdog will also improve his script if indeed that is required?YES, I mentioned all that, now if you wouldn't mind please answer the question, cheers.
@echo offcd C:\cls:inputset input=:: Check for xmlsif not exist "*.xml" ( echo No .xml files. pause >nul exit):: Set input to last .xml in dirfor /f "usebackq delims=" %%I in (`dir /b /a:-d /o:-d *.xml`) do ( set input=%%~nI goto output):output:: Grab 'actual' name of pdf from xmlset output=for /f "usebackq tokens=4 delims='" %%I in ("%input%.xml") do ( set output=%%I goto copy):copycopy "%input%.pdf" "D:\%output%.pdf"pause
Option ExplicitOn Error Resume NextDim objFSO,objFile,objRE,colMatches,oMatchesDim myFiles, srcFolder, dstFolder,dstFile,line,strToFind,strFileNameDim pdfBase,xmlBase,i,strFileContentsDim pdfStore(),pdfFullStore() 'define some array to store pathsSet objFSO = CreateObject("Scripting.FileSystemObject")' Create regexp Set objRE = New RegExpobjRE.Global = TrueobjRE.IgnoreCase = FalseobjRE.Pattern = "\[@name=(.*?)\]" 'pattern to search forsrcFolder="c:\temp" 'Server source folder locationdstFolder="c:\temp" 'Destination Folder as desiredi=0 'array counterFor Each myFiles In objFSO.GetFolder(srcFolder).Files If objFSO.GetExtensionName(myFiles) = "pdf" Then pdfBase = objFSO.GetBaseName(myFiles) ReDim Preserve pdfStore(i) ReDim Preserve pdfFullStore(i) pdfStore(i)=pdfBase pdfFullStore(i)=myFiles i=i+1 End If NextFor Each myFiles In objFSO.GetFolder(srcFolder).Files If objFSO.GetExtensionName(myFiles) = "xml" Then xmlBase = objFSO.GetBaseName(myFiles) For i=LBound(pdfStore) To UBound(pdfStore) If pdfStore(i) = xmlBase Then WScript.Echo "found " , xmlBase, pdfStore(i) Set objFile=objFSO.OpenTextFile(myFiles,1) strFileContents = objFile.ReadAll objFile.Close Set colMatches = objRE.Execute(strFileContents) Set oMatches = colMatches(1) If Len(oMatches) = 0 Then WScript.Echo "@name not found" Else strToFind = Replace(oMatches,"[@name='","") strToFind = Replace(strToFind,"']","") WScript.Echo "The string to replace is ",strToFind dstFile = dstFolder&"\"&strToFind WScript.Echo dstFile WScript.Echo "Renaming pdf ..." objFSO.MoveFile pdfFullStore(i),dstFile&".pdf" End If Set objFile=Nothing Set oMatches=Nothing Set colMatches=Nothing End If Next End If Next
<reportSearchPath>/content/package[@name='Provider']/report[@name='Report_test1']</reportSearchPath>