Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Open and Reading the file  (Read 39102 times)

0 Members and 1 Guest are viewing this topic.

srujana

  • Guest
Open and Reading the file
« on: August 15, 2007, 10:46:37 PM »
Hi,

 There is a requirement where files have to be renamed and moved to a new location. These files are cognos reports which are stored as two files

 - > One is the actual report
 - > Second is the description file which contains the actual name of the report. This is an XML file.

The description and the report files are stored with a random sequence number as file name.

The requirement is detailed as below:

1. The description file for the corres report has to be opened and browsed for the actual report name.

2. This report name is to be stored in a temporary variable and the report has to be renamed with this name.

3. The renamed file has to be moved from the current location (say C:\sample) to a new location (D:\)

I am trying to create a batch file for the above requirement. I have tried moving the file from one location to the other, but am not aware as how to open and read the XML file contents.

Could you please provide me with suitable DOS commands which will help me achieve the requirement.
Early response would be appreciated.

Thanks in advance,
Srujana

DeltaSlaya



    Apprentice
  • Google
    Re: Open and Reading the file
    « Reply #1 on: August 16, 2007, 12:03:11 AM »
    To open the file you should be able to simply write it's name and whatever it it's extension is assigned to should open it. If this doesn't work you can try writing the path to the executable and then the name of the file you want to open.

    To open a file in notepad manually.

    Quote
    C:\>notepad filename

    If you want to do this as an automated procedure I need more information.

    So firstly, the description file has to be opened ".xml". How would this be distinguished from others? Date? Only one in folder? Modified by Date?

    Secondly the report name has to be obtained from this file. What line is the name on, how many lines are there? Can you post an accurate example?

    Then the name has to be used to rename that same file? I don't understand? Does that actual report have an 'incorrect' name? If so then that needs to be identified too..

    Moving it is easy enough but I don't know what name is going where, please clarify and tell me if the above assumptions are correct. :P
    System specs:
    Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
    ASUS Striker Extreme
    XFX 8600GT XXX Edition
    2x 1gB Corsair XMS2 DDR2-800
    Seagate Barracuda 320gB SATA
    Raidmax Ninja 918 (520W ATXV2.0 PSU)
    -

    ghostdog74



      Specialist

      Thanked: 27
      Re: Open and Reading the file
      « Reply #2 on: August 16, 2007, 02:03:06 AM »
      it is better to show:
      a) example file names that you currently have
      b) things to search for in your files...and what you want to do with it.
      b) examples of expected output

      srujana

      • Guest
      Re: Open and Reading the file
      « Reply #3 on: August 16, 2007, 02:55:26 AM »
      Hi,

       Thanks for your responses. The requirement is explained below:
       
       Aim: To move Cognos reports from one location to other.
       
       The Cognos reports are stored in the Server as "PDF" files with a default name which is actually a random number sequence, for eg., 1325_1834940
       
      Apart from this file, a description file exists which is nothing but an "XML" file. In this XML file, we will find the actual report name, which may be present anywhere in the XML code.

      Now, our task is to open the XML file find that report name, store it in a temporary variable and rename the PDF file with that name.

      After this, the renamed PDF file has to be moved to another location.

      For eg., for a Cognos report  "Rep1_test", two files exist in the current location:

        1325_123467.xml
        1325_123467.pdf

      The XML file will contain the actual name which is "Rep1_test" in the XML code which has to be searched for and with which the PDF file has to be renamed.

      I hope the above explanation is clear, if not let me know.

      Thanks,
      Srujana
       

      DeltaSlaya



        Apprentice
      • Google
        Re: Open and Reading the file
        « Reply #4 on: August 16, 2007, 03:13:33 AM »
        Yes, thats a lot more clear but starting to border on the limits of my ability.

        You haven't answered how it would be decided what xml and pdf files are going to be used in the batch? Is the name stored in a variable or would it be entered, or would it be the most recently modified?

        Also, the actual name has to have something that makes it findable. If it is in a random location it will be impossible to locate and assign to a variable. Is it always on the same line? Does the line it is on have an identifier that will always be the same or what?

        This is what I understand so far:

        Quote
        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:\
        System specs:
        Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
        ASUS Striker Extreme
        XFX 8600GT XXX Edition
        2x 1gB Corsair XMS2 DDR2-800
        Seagate Barracuda 320gB SATA
        Raidmax Ninja 918 (520W ATXV2.0 PSU)
        -

        srujana

        • Guest
        Re: Open and Reading the file
        « Reply #5 on: August 16, 2007, 03:45:25 AM »
        Thanks for a prompt response. Our script would be triggered after a process places the scheduled reports (XML and PDF) in the server. As and when they're placed, our script should perform the required tasks and place the renamed PDF file in the desired location.

        Hence, our script will have XML and PDF files as input parameters (generic) and PDF file as output.

        Regarding the search criteria of the name, the report name would be found after the second "@name" statement in the xml code. The code is given below:

         <reportSearchPath>/content/package[@name='Provider']/report[@name='Report_test1']</reportSearchPath>
          <reportViewSearchPath>/content/folder[@name='COGNOS-DEV Team']/reportView[@name='Report View of Report_test1']</reportViewSearchPath>

         
        Thanks .....

        ghostdog74



          Specialist

          Thanked: 27
          Re: Open and Reading the file
          « Reply #6 on: August 16, 2007, 04:20:45 AM »
          Code: [Select]
          Option Explicit
          Dim objFSO,objFile,line,strToFind
          Dim myFiles, srcFolder, dstFile
          Dim pdfBase,xmlBase,i
          Set objFSO = CreateObject("Scripting.FileSystemObject")
          srcFolder="c:\temp" 'Server location
          strToFind = "Rep1_test" 'Enter string you want to find'
          dstFile = "c:\temp\"&strToFind 'this is file to rename to
          Dim pdfStore(),pdfFullStore()
          i=0
          For 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
          Next
          For 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
          save as myscript.vbs and run from command line , cscript /nologo myscript.vbs.

          srujana

          • Guest
          Re: Open and Reading the file
          « Reply #7 on: August 16, 2007, 04:25:22 AM »
          Thank you for the code. I shall try and get back to you in case of any clarifications.

           :)

          DeltaSlaya



            Apprentice
          • Google
            Re: Open and Reading the file
            « Reply #8 on: August 16, 2007, 04:41:03 AM »
            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.

            Quote
            strToFind = "Rep1_test" 'Enter string you want to find'
            dstFile = "c:\temp\"&strToFind 'this is file to rename to
            If 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?
            System specs:
            Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
            ASUS Striker Extreme
            XFX 8600GT XXX Edition
            2x 1gB Corsair XMS2 DDR2-800
            Seagate Barracuda 320gB SATA
            Raidmax Ninja 918 (520W ATXV2.0 PSU)
            -

            srujana

            • Guest
            Re: Open and Reading the file
            « Reply #9 on: August 16, 2007, 04:48:03 AM »
            As mentioned previosuly, the search criteria is not fixed. In the sense, it is not static and keeps changing as any report can be placed in the server at any time.

            Hence, strToFind = "Rep1_test" 'Enter string you want to find'
            statement has to be generic in nature.

            The report name is present after the second "@name" statement in the xml code. See the below code again:

            <reportSearchPath>/content/package[@name='Provider']/report[@name='Report_test1']</reportSearchPath>
              <reportViewSearchPath>/content/folder[@name='COGNOS-DEV Team']/reportView[@name='Report View of Report_test1']</reportViewSearchPath>

            Thanks.

            DeltaSlaya



              Apprentice
            • Google
              Re: Open and Reading the file
              « Reply #10 on: August 16, 2007, 04:50:47 AM »
              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.

              Quote
              strToFind = "Rep1_test" 'Enter string you want to find'
              dstFile = "c:\temp\"&strToFind 'this is file to rename to
              If 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.
              System specs:
              Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
              ASUS Striker Extreme
              XFX 8600GT XXX Edition
              2x 1gB Corsair XMS2 DDR2-800
              Seagate Barracuda 320gB SATA
              Raidmax Ninja 918 (520W ATXV2.0 PSU)
              -

              srujana

              • Guest
              Re: Open and Reading the file
              « Reply #11 on: August 16, 2007, 05:09:13 AM »
              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.

              Quote
              strToFind = "Rep1_test" 'Enter string you want to find'
              dstFile = "c:\temp\"&strToFind 'this is file to rename to
              If 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.


              Those .xml / .pdf files are considered which are placed in the server by a process.
              Hence, these files can be more than one in number.
              For eg., if two reports have been scheduled a process places a '.xml /.pdf ' for each of the reports in the server. 
              Hence, our trigger point would be the last modified date/time of the folder.
              So, every time a report is scheduled and placed this script has to be invoked.
              So, if the process runs 100times in a day, this script is also invoked those many times.

              I hope this answers your question... let me know in case of further clarity.

              DeltaSlaya



                Apprentice
              • Google
                Re: Open and Reading the file
                « Reply #12 on: August 16, 2007, 05:23:36 AM »
                Quote
                @echo off

                cd C:\
                cls

                :input
                set input=

                :: Check for xmls
                if not exist "*.xml" (
                   echo No .xml files.
                   pause >nul
                   exit
                )

                :: Set input to last .xml in dir
                for /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 xml
                set output=
                for /f "usebackq tokens=4 delims='" %%I in ("%input%.xml") do (
                   set output=%%I
                   goto copy
                )

                :copy
                copy "%input%.pdf" "D:\%output%.pdf"
                pause

                That should work. Grabs filename (without ext) of newest xml (gives error if none exist) then looks in %input%.xml, using tokens finds the actual name. Then setting this name as the output it copies %input%.pdf to D:\%output%.pdf. I believe that is correct?

                Input folder has been set as C: in example, please change only the "CD ..." line to go to the INPUT directory.
                Output folder is D:\.

                Tell me first what the folders should be but otherwise that worked fine for me with your example xml file and a pdf file with same name.
                System specs:
                Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                ASUS Striker Extreme
                XFX 8600GT XXX Edition
                2x 1gB Corsair XMS2 DDR2-800
                Seagate Barracuda 320gB SATA
                Raidmax Ninja 918 (520W ATXV2.0 PSU)
                -

                ghostdog74



                  Specialist

                  Thanked: 27
                  Re: Open and Reading the file
                  « Reply #13 on: August 16, 2007, 08:52:42 AM »
                  it certainly pays to describe your problem as clearly as possible.
                  Code: [Select]
                  Option Explicit
                  On Error Resume Next
                  Dim objFSO,objFile,objRE,colMatches,oMatches
                  Dim myFiles, srcFolder, dstFolder,dstFile,line,strToFind,strFileName
                  Dim pdfBase,xmlBase,i,strFileContents
                  Dim pdfStore(),pdfFullStore() 'define some array to store paths
                  Set objFSO = CreateObject("Scripting.FileSystemObject")
                  ' Create regexp
                  Set objRE = New RegExp
                  objRE.Global     = True
                  objRE.IgnoreCase = False
                  objRE.Pattern    = "\[@name=(.*?)\]" 'pattern to search for
                  srcFolder="c:\temp" 'Server source folder location
                  dstFolder="c:\temp" 'Destination Folder as desired
                  i=0 'array counter
                  For 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
                  Next
                  For 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

                  DeltaSlaya



                    Apprentice
                  • Google
                    Re: Open and Reading the file
                    « Reply #14 on: August 16, 2007, 02:02:04 PM »
                    There, you have two options, I don't know how similar in actions ghostdog's is to mine. Though mine definitely has less code and looks easier to follow.

                    I did make one assumption though.

                    Quote
                    <reportSearchPath>/content/package[@name='Provider']/report[@name='Report_test1']</reportSearchPath>

                    That all four of those " ' " apostrophes will always be on the FIRST line in the xml, with the real report name within the third and fourth. I chose to do it this way because another way the apostrophes would have been captured in the variable.
                    System specs:
                    Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                    ASUS Striker Extreme
                    XFX 8600GT XXX Edition
                    2x 1gB Corsair XMS2 DDR2-800
                    Seagate Barracuda 320gB SATA
                    Raidmax Ninja 918 (520W ATXV2.0 PSU)
                    -

                    srujana

                    • Guest
                    Re: Open and Reading the file
                    « Reply #15 on: August 17, 2007, 02:49:20 AM »
                    Both,

                     Thanks for your responses. But, I have a problem here. I am unable to run the VB script. I tried executing it from command line but nothing seems to be happening.

                    I also tried to run batch file, but it just executes till changing the directory and then displays the following message:

                     The system cannot find the file specified.
                     Press any key to continue . . .


                    Could you please help me ... ???

                    Thanks...
                    Srujana

                    DeltaSlaya



                      Apprentice
                    • Google
                      Re: Open and Reading the file
                      « Reply #16 on: August 17, 2007, 02:54:31 AM »
                      As I said, you will need to tell me what folders are used. The real folders, not examples. Thanks.
                      System specs:
                      Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                      ASUS Striker Extreme
                      XFX 8600GT XXX Edition
                      2x 1gB Corsair XMS2 DDR2-800
                      Seagate Barracuda 320gB SATA
                      Raidmax Ninja 918 (520W ATXV2.0 PSU)
                      -

                      DeltaSlaya



                        Apprentice
                      • Google
                        Re: Open and Reading the file
                        « Reply #17 on: August 17, 2007, 03:00:28 AM »
                        Quote
                        That should work. Grabs filename (without ext) of newest xml (gives error if none exist) then looks in %input%.xml, using tokens finds the actual name. Then setting this name as the output it copies %input%.pdf to D:\%output%.pdf. I believe that is correct?

                        Input folder has been set as C: in example, please change only the "CD ..." line to go to the INPUT directory.
                        Output folder is D:\.

                        Tell me first what the folders should be but otherwise that worked fine for me with your example xml file and a pdf file with same name.

                        Answer all that, is it correct?
                        System specs:
                        Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                        ASUS Striker Extreme
                        XFX 8600GT XXX Edition
                        2x 1gB Corsair XMS2 DDR2-800
                        Seagate Barracuda 320gB SATA
                        Raidmax Ninja 918 (520W ATXV2.0 PSU)
                        -

                        srujana

                        • Guest
                        Re: Open and Reading the file
                        « Reply #18 on: August 17, 2007, 03:03:38 AM »
                        Everything is right. As of now, I am trying to test the program in my local folders and I made the changes accordingly. But, I donot understand the reason as to why its not being executed.

                        DeltaSlaya



                          Apprentice
                        • Google
                          Re: Open and Reading the file
                          « Reply #19 on: August 17, 2007, 03:05:20 AM »
                          Ok remove the @echo off line at the top of the script, run it again. Then right click on the window click 'MARK'. Select everything, make sure you have everything and then press 'ENTER'. You will then be able to paste that information here, thanks.
                          System specs:
                          Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                          ASUS Striker Extreme
                          XFX 8600GT XXX Edition
                          2x 1gB Corsair XMS2 DDR2-800
                          Seagate Barracuda 320gB SATA
                          Raidmax Ninja 918 (520W ATXV2.0 PSU)
                          -

                          DeltaSlaya



                            Apprentice
                          • Google
                            Re: Open and Reading the file
                            « Reply #20 on: August 17, 2007, 03:08:02 AM »
                            Also post if possible a "dir" of the input folder and the contents of the xml file. I will figure out where I went wrong. You didn't answer if the line which has the actual name is always the first and has four 's with the name between the THIRD and FOURTH.
                            System specs:
                            Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                            ASUS Striker Extreme
                            XFX 8600GT XXX Edition
                            2x 1gB Corsair XMS2 DDR2-800
                            Seagate Barracuda 320gB SATA
                            Raidmax Ninja 918 (520W ATXV2.0 PSU)
                            -

                            ghostdog74



                              Specialist

                              Thanked: 27
                              Re: Open and Reading the file
                              « Reply #21 on: August 17, 2007, 03:24:06 AM »
                              I am unable to run the VB script. I tried executing it from command line but nothing seems to be happening.
                              how did you execute it? it should be : cscript /nologo myscript.vbs. try to put your script in the same directory as the files. Also change the script's srcFolder, dstFolder etc....according to your environment..? Don't just cut and paste...and expect it to work...

                              srujana

                              • Guest
                              Re: Open and Reading the file
                              « Reply #22 on: August 17, 2007, 03:24:24 AM »
                              Hi,
                               
                               This is the output:

                               C:\log>set input=

                              C:\log>if not exist "*.xml" (
                              echo No .xml files.
                               pause  1>nul
                               exit
                              )

                              C:\log>for /F "usebackq delims=" %I in (`dir /b /a:-d /o:-d *.xml`) do (
                              set input=%~nI
                               goto output
                              )

                              C:\log>(
                              set input=Test
                               goto output
                              )

                              C:\log>set output=

                              C:\log>for /F "usebackq tokens=4 delims='" %I in ("Test.xml") do (
                              set output=%I
                               goto copy
                              )

                              C:\log>copy "Test.pdf" "D:\.pdf"
                              The system cannot find the file specified.

                              C:\log>pause
                              Press any key to continue . . .

                              C:\log>



                              I created a folder called  "log" in C:\ drive. And, placed two files
                               Test.xml
                               123.pdf

                              But, the program seems to be renaming the pdf with "Test".

                              Please look into the same., thanks

                              srujana

                              • Guest
                              Re: Open and Reading the file
                              « Reply #23 on: August 17, 2007, 03:25:41 AM »
                              Ghostdog, I made the modifications accordingly and only then tried executing the VBS file. But, nothing seems to be happening.

                              DeltaSlaya



                                Apprentice
                              • Google
                                Re: Open and Reading the file
                                « Reply #24 on: August 17, 2007, 03:27:26 AM »
                                JESUS CHRIST. You said the pdf file and the xml will always have the same name... Try rename them to both the same name and it will work...

                                If they are not always going to both be the same then tell me and I will rewrite it a bit but that will take a while and may be less reliable. Try making the xml and pdf with same name..

                                Quote
                                For eg., for a Cognos report  "Rep1_test", two files exist in the current location:

                                  1325_123467.xml
                                  1325_123467.pdf
                                System specs:
                                Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                ASUS Striker Extreme
                                XFX 8600GT XXX Edition
                                2x 1gB Corsair XMS2 DDR2-800
                                Seagate Barracuda 320gB SATA
                                Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                -

                                DeltaSlaya



                                  Apprentice
                                • Google
                                  Re: Open and Reading the file
                                  « Reply #25 on: August 17, 2007, 03:32:40 AM »
                                  Sorry for the language but I'm just relieved that it wasn't my fault lol.

                                  Why didn't the code you copied have the 'cd ...' line?
                                  System specs:
                                  Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                  ASUS Striker Extreme
                                  XFX 8600GT XXX Edition
                                  2x 1gB Corsair XMS2 DDR2-800
                                  Seagate Barracuda 320gB SATA
                                  Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                  -

                                  srujana

                                  • Guest
                                  Re: Open and Reading the file
                                  « Reply #26 on: August 17, 2007, 03:35:55 AM »
                                  Yes,both the files exist with the same name. But, the program has to rename the PDF with the name present in the XML code (2nd @name) which it isnt doing.

                                  DeltaSlaya



                                    Apprentice
                                  • Google
                                    Re: Open and Reading the file
                                    « Reply #27 on: August 17, 2007, 03:38:39 AM »
                                    Well it worked fine for me when I tested it.

                                    You MUST have an xml and a pdf file with the same name in the folder that it is CDing to.

                                    Please post the contents of the xml file here. Because it's not grabbing the name.

                                    And please start reading my posts and answering all questions so I don't have to keep reposting the same ones, thanks.
                                    System specs:
                                    Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                    ASUS Striker Extreme
                                    XFX 8600GT XXX Edition
                                    2x 1gB Corsair XMS2 DDR2-800
                                    Seagate Barracuda 320gB SATA
                                    Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                    -

                                    srujana

                                    • Guest
                                    Re: Open and Reading the file
                                    « Reply #28 on: August 17, 2007, 03:46:24 AM »
                                    Ghost dog, this the output after running your script.

                                    I included the execute statement in a batch file and ran it.

                                    C:\log>cd\

                                    C:\>batch_vbs.bat

                                    C:\>CD C:\log

                                    C:\log>cscript /nologo C:\log\vbs_text.vbs
                                    found  123 123
                                    The string to replace is  [@name=&apos;PRV-INT-001:Provider NCPDP Interface Erro
                                    r Report&apos;]
                                    d:\\[@name=&apos;PRV-INT-001:Provider NCPDP Interface Error Report&apos;]
                                    Renaming pdf ...
                                    C:\log>


                                    DeltaSlaya



                                      Apprentice
                                    • Google
                                      Re: Open and Reading the file
                                      « Reply #29 on: August 17, 2007, 03:49:17 AM »
                                      Please post A REAL example of an xml file used. Because judging by that script you have just posted it appears that 's are not always present. If you ANSWERED my question I would have used an alternative method.

                                      Please post the xml and identify the name the pdf is to be changed to and two characters either side of it that will NEVER change..

                                      Thanks, please make sure you are answering all those questions.
                                      System specs:
                                      Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                      ASUS Striker Extreme
                                      XFX 8600GT XXX Edition
                                      2x 1gB Corsair XMS2 DDR2-800
                                      Seagate Barracuda 320gB SATA
                                      Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                      -

                                      srujana

                                      • Guest
                                      Re: Open and Reading the file
                                      « Reply #30 on: August 17, 2007, 03:57:16 AM »
                                      Delta,

                                       I have placed following files in C:\log

                                       123.xml
                                       123.pdf

                                      The XML code is as below:

                                       <?xml version="1.0" encoding="utf-8" ?>
                                      - <!--   Copyright (C) 2006 Cognos Incorporated.  All Rights Reserved.
                                        Cognos (R) is a trademark of Cognos Incorporated.

                                        -->
                                      - <!--   Experimental.
                                        Product features described in this file may not be supported in future releases.

                                        -->
                                      - <outputDescriptor xmlns="http://developer.cognos.com/schema/OutputDescriptor/1.0" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                                        <asOfTime>2007-08-12T13:38:08.093Z</asOfTime>
                                        <burstKey />
                                        <contact />
                                        <defaultDescription />
                                        <defaultName>2007-08-12T13:38:09.078Z</defaultName>
                                        <fileName>1376_1186940289078.pdf</fileName>
                                        <locale>en-us</locale>
                                        <owner>rgajendra</owner>
                                        <ownerNamespace>COGNOS-DEV Team</ownerNamespace>
                                        <parameterValues />
                                        <reportSearchPath>/content/package[@name='Provider']/report[@name='PRV-INT-001:Provider NCPDP Interface Error Report']</reportSearchPath>
                                        <reportViewSearchPath>/content/folder[@name='COGNOS-DEV Team']/reportView[@name='Report View of PRV-INT-001:Provider NCPDP Interface Error Report']</reportViewSearchPath>
                                        </outputDescriptor>

                                      The name the PDF is to be changed to is:

                                      PRV-INT-001:Provider NCPDP Interface Error Report.

                                      The ' ' on either side of the name would never change.

                                      Thanks...

                                      DeltaSlaya



                                        Apprentice
                                      • Google
                                        Re: Open and Reading the file
                                        « Reply #31 on: August 17, 2007, 04:02:14 AM »
                                        Will the line always be on 21 or will it be the only line that has a @name OR 'reportsearchpath' on it, or both? And are there always FOUR ' on that line?
                                        System specs:
                                        Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                        ASUS Striker Extreme
                                        XFX 8600GT XXX Edition
                                        2x 1gB Corsair XMS2 DDR2-800
                                        Seagate Barracuda 320gB SATA
                                        Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                        -

                                        srujana

                                        • Guest
                                        Re: Open and Reading the file
                                        « Reply #32 on: August 17, 2007, 04:05:09 AM »
                                        It will be the only line which has @name in it, which is second in the order.

                                        DeltaSlaya



                                          Apprentice
                                        • Google
                                          Re: Open and Reading the file
                                          « Reply #33 on: August 17, 2007, 04:10:57 AM »
                                          Ok will it also be the only line with "reportSearchPath" on it, because that would be easier to find.
                                          System specs:
                                          Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                          ASUS Striker Extreme
                                          XFX 8600GT XXX Edition
                                          2x 1gB Corsair XMS2 DDR2-800
                                          Seagate Barracuda 320gB SATA
                                          Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                          -

                                          srujana

                                          • Guest
                                          Re: Open and Reading the file
                                          « Reply #34 on: August 17, 2007, 04:12:32 AM »
                                          Yes.

                                          DeltaSlaya



                                            Apprentice
                                          • Google
                                            Re: Open and Reading the file
                                            « Reply #35 on: August 17, 2007, 04:35:55 AM »
                                            Filenames cannot contain ":". Thats why the batch wasn't working.
                                            System specs:
                                            Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                            ASUS Striker Extreme
                                            XFX 8600GT XXX Edition
                                            2x 1gB Corsair XMS2 DDR2-800
                                            Seagate Barracuda 320gB SATA
                                            Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                            -

                                            srujana

                                            • Guest
                                            Re: Open and Reading the file
                                            « Reply #36 on: August 17, 2007, 04:37:59 AM »
                                            Oh..k so is there no other alternative?

                                            DeltaSlaya



                                              Apprentice
                                            • Google
                                              Re: Open and Reading the file
                                              « Reply #37 on: August 17, 2007, 04:40:54 AM »
                                              Yes I can change the : to an alternative character before the file is renamed, what would you like unusable characters to be altered to? The unusable characters are: "\ / : ? " < > |" but "< > |" will cause the batch file to crash anyway.
                                              System specs:
                                              Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                              ASUS Striker Extreme
                                              XFX 8600GT XXX Edition
                                              2x 1gB Corsair XMS2 DDR2-800
                                              Seagate Barracuda 320gB SATA
                                              Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                              -

                                              srujana

                                              • Guest
                                              Re: Open and Reading the file
                                              « Reply #38 on: August 17, 2007, 04:50:45 AM »
                                              Can you change the character to '-' (hiphen)

                                              DeltaSlaya



                                                Apprentice
                                              • Google
                                                Re: Open and Reading the file
                                                « Reply #39 on: August 17, 2007, 04:53:50 AM »
                                                Yes. What of those characters may be present? Just the :?
                                                System specs:
                                                Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                ASUS Striker Extreme
                                                XFX 8600GT XXX Edition
                                                2x 1gB Corsair XMS2 DDR2-800
                                                Seagate Barracuda 320gB SATA
                                                Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                -

                                                DeltaSlaya



                                                  Apprentice
                                                • Google
                                                  Re: Open and Reading the file
                                                  « Reply #40 on: August 17, 2007, 04:58:52 AM »
                                                  Quote
                                                  @echo off

                                                  :: Change "C:\OUTPUT" to output directory with NO "\" at end.
                                                  set outdir=C:\OUTPUT
                                                  if not exist "%outdir%" (
                                                     echo Output folder not exist.
                                                     pause >nul
                                                     exit
                                                  )

                                                  :: Change "C:\" to input directory with "\" at end.
                                                  cd C:\

                                                  cls

                                                  set input=

                                                  :: Check for xmls
                                                  if not exist "*.xml" (
                                                     echo No .xml files.
                                                     pause >nul
                                                     exit
                                                  )

                                                  :: Set input to last modified .xml in dir
                                                     for /f "usebackq delims=" %%I in (`dir /b /a:-d /o:-d *.xml`) do (
                                                     set input=%%~nI
                                                     goto out
                                                  )

                                                  :out

                                                  :: Grab 'actual' name of pdf from xml
                                                  set output=

                                                  for /f "usebackq tokens=4 delims='" %%I in (`findstr /i "reportSearchPath" "%input%.xml"`) do (
                                                     set output=%%I
                                                     goto copy
                                                  )

                                                  :copy
                                                  set output=%output::=-%
                                                  copy "%input%.pdf" "%outdir%\%output%.pdf"
                                                  pause

                                                  There you go.. Don't forget to change the input and output folders according to the information.
                                                  System specs:
                                                  Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                  ASUS Striker Extreme
                                                  XFX 8600GT XXX Edition
                                                  2x 1gB Corsair XMS2 DDR2-800
                                                  Seagate Barracuda 320gB SATA
                                                  Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                  -

                                                  srujana

                                                  • Guest
                                                  Re: Open and Reading the file
                                                  « Reply #41 on: August 17, 2007, 05:13:18 AM »
                                                  Hey! this is the output, it still seems to consider the XML name and not the name inside it...


                                                  C:\log>set input=

                                                  C:\log>if not exist "*.xml" (
                                                  echo No .xml files.
                                                   pause  1>nul
                                                   exit
                                                  )

                                                  C:\log>for /F "usebackq delims=" %I in (`dir /b /a:-d /o:-d *.xml`) do (
                                                  set input=%~nI
                                                   goto out
                                                  )

                                                  C:\log>(
                                                  set input=123
                                                   goto out
                                                  )

                                                  C:\log>set output=

                                                  C:\log>for /F "usebackq tokens=4 delims='" %I in (`findstr /i "reportSearchPath
                                                   "123.xml"`) do (
                                                  set output=%I
                                                   goto copy
                                                  )

                                                  C:\log>set output=:=-

                                                  C:\log>copy "123.pdf" "D:\:=-.pdf"
                                                  The filename, directory name, or volume label syntax is incorrect.
                                                          0 file(s) copied.

                                                  C:\log>pause
                                                  Press any key to continue . . .

                                                  C:\log>

                                                  DeltaSlaya



                                                    Apprentice
                                                  • Google
                                                    Re: Open and Reading the file
                                                    « Reply #42 on: August 17, 2007, 05:17:29 AM »
                                                    Hmmm, that works for me, are you sure the line format is the same as this?

                                                    "<reportSearchPath>/content/package[@name='Provider']/report[@name='PRV-INT-001:Provider NCPDP Interface Error Report']</reportSearchPath>"

                                                    Try replacting the "reportSearchPath" for "@name" in the second for statement.
                                                    System specs:
                                                    Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                    ASUS Striker Extreme
                                                    XFX 8600GT XXX Edition
                                                    2x 1gB Corsair XMS2 DDR2-800
                                                    Seagate Barracuda 320gB SATA
                                                    Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                    -

                                                    srujana

                                                    • Guest
                                                    Re: Open and Reading the file
                                                    « Reply #43 on: August 17, 2007, 06:03:58 AM »
                                                    Hey! it still doesnt work :(

                                                    ghostdog74



                                                      Specialist

                                                      Thanked: 27
                                                      Re: Open and Reading the file
                                                      « Reply #44 on: August 17, 2007, 09:11:35 AM »
                                                      Ghostdog, I made the modifications accordingly and only then tried executing the VBS file. But, nothing seems to be happening.
                                                      show me your version of the vb script. Also, don't just say not happening. describe in more detail. does it mean you did not see the changed file? or it does change but not to your specs?  for me it works.

                                                      DeltaSlaya



                                                        Apprentice
                                                      • Google
                                                        Re: Open and Reading the file
                                                        « Reply #45 on: August 17, 2007, 04:41:15 PM »
                                                        Ok I'm not going to continue helping you because you are not answering my questions.

                                                        The batch file I have supplied you works fine under the following circumstances.

                                                        • There are two file in the directory which is in the 'CD directory' line
                                                        • One file is a .xml and the other a .pdf, both must have the same name before the extension.
                                                        • The .xml which the task is to be performed on must be the most recently modified in the folder.
                                                        • The line in the .xml file must be the only one with 'reportSearchPath' on it. The name is always between the third and fourth " ' ".
                                                        • The actual name must not contain invalid characters, ":" is catered for but "< > |" are impossible.
                                                        • The output folder specified MUST exist, try make it the same case as well.

                                                        The problem you are seeing is that the text in the .xml is not being extracted AT all.

                                                        This is what I see when I use the example .xml you posted, files are test.pdf and test.xml.

                                                        Quote
                                                        C:\>set input=

                                                        C:\>if not exist "*.xml" (
                                                        echo No .xml files.
                                                         pause  1>nul
                                                         exit
                                                        )

                                                        C:\>for /F "usebackq delims=" %I in (`dir /b /a:-d /o:-d *.xml`) do (
                                                        set input=%~nI
                                                         goto out
                                                        )

                                                        C:\>(
                                                        set input=test
                                                         goto out
                                                        )

                                                        C:\>set output=

                                                        C:\>for /F "usebackq tokens=4 delims='" %I in (`findstr /i "reportSearchPath" "test.xml"`) do (
                                                        set output=%I
                                                         goto copy
                                                        )

                                                        C:\>(
                                                        set output=PRV-INT-001:Provider NCPDP Interface Error Report
                                                         goto copy
                                                        )

                                                        C:\>set output=PRV-INT-001-Provider NCPDP Interface Error Report

                                                        C:\>copy "test.pdf" "C:\OUTPUT\PRV-INT-001-Provider NCPDP Interface Error Report
                                                        .pdf"
                                                                1 file(s) copied.

                                                        C:\>pause
                                                        Press any key to continue . . .

                                                        As you can see it has worked perfectly. You must have not described the layout of the .xml files completely.

                                                        READ THIS: Can you please post an example of the .xml file you are trying and failing on. esp the line with the actual name on it.
                                                        System specs:
                                                        Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                        ASUS Striker Extreme
                                                        XFX 8600GT XXX Edition
                                                        2x 1gB Corsair XMS2 DDR2-800
                                                        Seagate Barracuda 320gB SATA
                                                        Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                        -

                                                        ghostdog74



                                                          Specialist

                                                          Thanked: 27
                                                          Re: Open and Reading the file
                                                          « Reply #46 on: August 17, 2007, 08:53:21 PM »
                                                          Code: [Select]
                                                          C:\temp>dir /B
                                                          1325_123467.pdf
                                                          1325_123467.xml
                                                          1325_123468.pdf
                                                          1325_123468.xml

                                                          C:\temp>more 1325_123467.xml
                                                          line1
                                                          line2
                                                          line3
                                                           <reportSearchPath>/content/package[@name='Provider']/report[@name='Report_test1]</reportSearchPath>
                                                            <reportViewSearchPath>/content/folder[@name='COGNOS-DEV Team']/reportView[@name='Report View of Re
                                                          port_test1']</reportViewSearchPath>
                                                          line blah
                                                          line blah blah

                                                          C:\temp>more 1325_123468.xml
                                                          dfvasdfs
                                                          sdfsddfgf
                                                          wfsdfdfhhe45gdfg

                                                           <reportSearchPath>/content/package[@name='Provider']/report[@name='Report_test2']</reportSearchPath>
                                                            <reportViewSearchPath>/content/folder[@name='COGNOS-DEV Team']/reportView[@name='Report View of Re
                                                          port_test1']</reportViewSearchPath>
                                                          sf

                                                          sdfsdfsdfsd
                                                          sdfsfsfddsghfbvsbxb

                                                          C:\temp>cd \

                                                          C:\>cd vbscript

                                                          C:\vbscript>cscript /nologo moveCognoReports.vbs
                                                          found  1325_123467 1325_123467
                                                          The string to replace is  Report_test1
                                                          c:\temp\Report_test1
                                                          Renaming pdf ...
                                                          found  1325_123468 1325_123468
                                                          The string to replace is  Report_test2
                                                          c:\temp\Report_test2
                                                          Renaming pdf ...

                                                          C:\vbscript>cd \temp

                                                          C:\temp>dir /B
                                                          1325_123467.xml
                                                          1325_123468.xml
                                                          Report_test1.pdf
                                                          Report_test2.pdf



                                                          DeltaSlaya



                                                            Apprentice
                                                          • Google
                                                            Re: Open and Reading the file
                                                            « Reply #47 on: August 18, 2007, 04:21:49 AM »
                                                            Yea how come we can get it to work and he can't? Is the OP's harddrive format FAT32 or something?
                                                            System specs:
                                                            Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                            ASUS Striker Extreme
                                                            XFX 8600GT XXX Edition
                                                            2x 1gB Corsair XMS2 DDR2-800
                                                            Seagate Barracuda 320gB SATA
                                                            Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                            -

                                                            srujana

                                                            • Guest
                                                            Re: Open and Reading the file
                                                            « Reply #48 on: August 20, 2007, 11:17:48 PM »
                                                            Hi,

                                                             Both the scripts are running without errors, but are not fetching the desired result.
                                                             My OS is WinXP. Will the OS factor have an affect on this?

                                                             Thanks....
                                                             Srujana

                                                            ghostdog74



                                                              Specialist

                                                              Thanked: 27
                                                              Re: Open and Reading the file
                                                              « Reply #49 on: August 20, 2007, 11:38:15 PM »
                                                              but are not fetching the desired result.
                                                              dude, what are the desired results.? did you see the file names changed? show what you did. try not to leave out any details. this is only common sense. If not , how to help you?

                                                              DeltaSlaya



                                                                Apprentice
                                                              • Google
                                                                Re: Open and Reading the file
                                                                « Reply #50 on: August 20, 2007, 11:44:26 PM »
                                                                Read ghostdog and myself's posts above, they clearly both indicate the procedure defined, using the example .xml template supplied are being followed correctly. Please also inform me if the points I have identified in that post are correct. You seem to have a tendency to skip over questions and misinform us, it is important that you tell me that the assumptions I have made are correct.
                                                                System specs:
                                                                Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                                ASUS Striker Extreme
                                                                XFX 8600GT XXX Edition
                                                                2x 1gB Corsair XMS2 DDR2-800
                                                                Seagate Barracuda 320gB SATA
                                                                Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                                -

                                                                srujana

                                                                • Guest
                                                                Re: Open and Reading the file
                                                                « Reply #51 on: August 21, 2007, 12:18:01 AM »
                                                                Hi,

                                                                 All the assumptions that are made are correct. I followed the same procedure to run the scripts. This is what I did:

                                                                Vb_Script:


                                                                C:\TEMP>dir /b
                                                                test.pdf
                                                                test.xml

                                                                C:\TEMP>more test.xml
                                                                <?xml version="1.0" encoding="utf-8"?>
                                                                <!--
                                                                  Copyright (C) 2006 Cognos Incorporated.  All Rights Reserved.
                                                                  Cognos (R) is a trademark of Cognos Incorporated.
                                                                -->
                                                                <!--
                                                                  Experimental.
                                                                  Product features described in this file may not be supported in future release
                                                                s.
                                                                -->
                                                                <outputDescriptor
                                                                                xmlns="http://developer.cognos.com/schema/OutputDescriptor/1.0"
                                                                                xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
                                                                                xmlns:xs="http://www.w3.org/2001/XMLSchema"
                                                                                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                                                                >
                                                                        <asOfTime>2007-08-12T13:38:08.093Z</asOfTime>
                                                                        <burstKey></burstKey>
                                                                        <contact/>
                                                                        <defaultDescription></defaultDescription>
                                                                        <defaultName>2007-08-12T13:38:09.078Z</defaultName>
                                                                        <fileName>1376_1186940289078.pdf</fileName>
                                                                        <locale>en-us</locale>
                                                                        <owner>rgajendra</owner>
                                                                        <ownerNamespace>COGNOS-DEV Team</ownerNamespace>
                                                                        <parameterValues/>
                                                                        <reportSearchPath>/content/package[@name=&apos;Provider&apos;]/report[@n
                                                                ame=&apos;PRV-INT-001:Provider NCPDP Interface Error Report&apos;]</reportSearch
                                                                Path>
                                                                        <reportViewSearchPath>/content/folder[@name=&apos;COGNOS-DEV Team&apos;]
                                                                /reportView[@name=&apos;Report View of PRV-INT-001:Provider NCPDP Interface Erro
                                                                r Report&apos;]</reportViewSearchPath>
                                                                </outputDescriptor>

                                                                C:\TEMP>cd \vbscript

                                                                C:\vbscript>cscript /nologo vb_script.vbs
                                                                found  test test
                                                                The string to replace is  [@name=&apos;PRV-INT-001:Provider NCPDP Interface Erro
                                                                r Report&apos;]
                                                                c:\temp\[@name=&apos;PRV-INT-001:Provider NCPDP Interface Error Report&apos;]
                                                                Renaming pdf ...

                                                                C:\vbscript>cd \temp

                                                                C:\TEMP>dir /b
                                                                test.pdf
                                                                test.xml

                                                                C:\TEMP>


                                                                Batch Script:

                                                                C:\>set input=

                                                                C:\>if not exist "*.xml" (
                                                                echo No .xml files.
                                                                 pause  1>nul
                                                                 exit
                                                                )

                                                                C:\>for /F "usebackq delims=" %I in (`dir /b /a:-d /o:-d *.xml`) do (
                                                                set input=%~nI
                                                                 goto out
                                                                )

                                                                C:\>(
                                                                set input=xml
                                                                 goto out
                                                                )

                                                                C:\>set output=

                                                                C:\>for /F "usebackq tokens=4 delims='" %I in (`findstr /i "reportSearchPath" "
                                                                ml.xml"`) do (
                                                                set output=%I
                                                                 goto copy
                                                                )

                                                                C:\>set output=:=-

                                                                C:\>copy "xml.pdf" "C:\:=-.pdf"
                                                                The system cannot find the file specified.

                                                                C:\>pause
                                                                Press any key to continue . . .

                                                                C:\>


                                                                Thanks...
                                                                Srujana

                                                                ghostdog74



                                                                  Specialist

                                                                  Thanked: 27
                                                                  Re: Open and Reading the file
                                                                  « Reply #52 on: August 21, 2007, 12:38:14 AM »
                                                                  Regarding the search criteria of the name, the report name would be found after the second "@name" statement in the xml code. The code is given below:
                                                                  <reportSearchPath>/content/package[@name='Provider']/report[@name='Report_test1']</reportSearchPath>
                                                                    <reportViewSearchPath>/content/folder[@name='COGNOS-DEV Team']/reportView[@name='Report View of Report_test1']</reportViewSearchPath>

                                                                  let's make this clear again. The report name is found in the tag <reportSearchPath> at the 2nd @name (Report_test),
                                                                  OR is it the <reportViewSearchPath> at 2nd @name (Report View of Report_test1) ? Also you have
                                                                  different xml format, in the sense that the <reportSearchPath> and <reportViewSearchPath> sometimes contains other characters, instead of a valid report name.

                                                                  In the latest example xml....you have :
                                                                  Code: [Select]
                                                                       <reportSearchPath>/content/package[@name=&apos;Provider&apos;]/report[@name=&apos;PRV-INT-001:Provider NCPDP Interface Error Report&apos;]</reportSearchPath>
                                                                          <reportViewSearchPath>/content/folder[@name=&apos;COGNOS-DEV Team&apos;]/reportView[@name=&apos;Report View of PRV-INT-001:Provider NCPDP Interface Error Report&apos;]</reportViewSearchPath>

                                                                  So WHAT is the correct report name you wish to get ??? if you take the 2nd @name for <reportSearchPath>, it is  "&apos;PRV-INT-001:Provider NCPDP Interface Error Report&apos;]" ...do you really want this as a file name?? if you take 2nd @name for <reportViewSearchPath>, its "&apos;Report View of PRV-INT-001:Provider NCPDP Interface Error Report&apos;]" ...

                                                                  srujana

                                                                  • Guest
                                                                  Re: Open and Reading the file
                                                                  « Reply #53 on: August 21, 2007, 12:44:49 AM »
                                                                  You are right, we have to consider the 2nd @name in <reportSearchPath>.
                                                                  And, coming to the Report Name, the actual report name doesn't have &apos
                                                                  in it. Its appearing only when am running the VB script.

                                                                  The correct report name I wish to get is: "PRV-INT-001:Provider NCPDP Interface Error Report"
                                                                  Find the actual xml contents below:

                                                                  <?xml version="1.0" encoding="utf-8" ?>
                                                                  - <!--
                                                                    Copyright (C) 2006 Cognos Incorporated.  All Rights Reserved.
                                                                    Cognos (R) is a trademark of Cognos Incorporated.


                                                                    -->
                                                                  - <!--
                                                                    Experimental.
                                                                    Product features described in this file may not be supported in future releases.


                                                                    -->
                                                                  - <outputDescriptor xmlns="http://developer.cognos.com/schema/OutputDescriptor/1.0" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                                                                    <asOfTime>2007-08-12T13:38:08.093Z</asOfTime>
                                                                    <burstKey />
                                                                    <contact />
                                                                    <defaultDescription />
                                                                    <defaultName>2007-08-12T13:38:09.078Z</defaultName>
                                                                    <fileName>1376_1186940289078.pdf</fileName>
                                                                    <locale>en-us</locale>
                                                                    <owner>rgajendra</owner>
                                                                    <ownerNamespace>COGNOS-DEV Team</ownerNamespace>
                                                                    <parameterValues />
                                                                    <reportSearchPath>/content/package[@name='Provider']/report[@name='PRV-INT-001:Provider NCPDP Interface Error Report']</reportSearchPath>
                                                                    <reportViewSearchPath>/content/folder[@name='COGNOS-DEV Team']/reportView[@name='Report View of PRV-INT-001:Provider NCPDP Interface Error Report']</reportViewSearchPath>
                                                                    </outputDescriptor>


                                                                  Thanks...

                                                                  ghostdog74



                                                                    Specialist

                                                                    Thanked: 27
                                                                    Re: Open and Reading the file
                                                                    « Reply #54 on: August 21, 2007, 01:55:31 AM »
                                                                    You are right, we have to consider the 2nd @name in <reportSearchPath>.
                                                                    And, coming to the Report Name, the actual report name doesn't have &apos
                                                                    in it. Its appearing only when am running the VB script.
                                                                    that's because in the original xml you provided, the file name is very simple, Report_test1. I assume its this format for all your xml files. Then came  the latest xml example from you, which has the &apos part ....you should have described the possible formats of that 2nd @name that can be parse. By the way, the reason why it does not work  is because you have a ":"  after the PRV-INT-001, Windows does not accept the semi colon. you have to get rid of it.
                                                                    Code: [Select]
                                                                    Option Explicit
                                                                    On Error Resume Next
                                                                    Dim objFSO,objFile,objRE,colMatches,oMatches
                                                                    Dim myFiles, srcFolder, dstFolder,dstFile,line,strToFind,strFileName
                                                                    Dim pdfBase,xmlBase,i,strFileContents
                                                                    Dim pdfStore(),pdfFullStore() 'define some array to store paths
                                                                    Set objFSO = CreateObject("Scripting.FileSystemObject")
                                                                    ' Create regexp
                                                                    Set objRE = New RegExp
                                                                    objRE.Global     = True
                                                                    objRE.IgnoreCase = False
                                                                    objRE.Pattern   = "\[(.*?)\]"
                                                                    srcFolder="c:\temp" 'Server source folder location
                                                                    dstFolder="c:\temp" 'Destination Folder as desired
                                                                    i=0 'array counter
                                                                    For 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
                                                                    Next
                                                                    For 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,"<reportSearchPath>") > 0 Then
                                                                    Set colMatches = objRE.Execute(line)
                                                                    Set oMatches = colMatches(1)
                                                                    If Len(oMatches) = 0 Then
                                                                        WScript.Echo "@name not found"
                                                                        Else
                                                                    strToFind= Replace(oMatches,"[@name=&apos;","")
                                                                    strToFind = Replace(strToFind,"&apos;]","")
                                                                    strToFind = Replace(strToFind,":","")
                                                                        WScript.Echo "The string to replace is ",strToFind
                                                                        dstFile = strToFind&".pdf"
                                                                        WScript.Echo dstFile
                                                                        WScript.Echo "Renaming pdf ..."
                                                                    objFSO.MoveFile pdfFullStore(i),dstFolder&"\"&dstFile
                                                                    End If

                                                                    End If
                                                                    Loop

                                                                    End If
                                                                    Next
                                                                    End If
                                                                    Next
                                                                    Set objFile=Nothing
                                                                    Set oMatches=Nothing
                                                                    Set colMatches=Nothing

                                                                    output:
                                                                    Code: [Select]
                                                                    C:\temp>dir /B
                                                                    test.pdf
                                                                    test.xml

                                                                    C:\temp>cscript /nologo c:\vbscript\MoveCogNosReports.vbs
                                                                    found  test test
                                                                    The string to replace is  PRV-INT-001Provider NCPDP Interface Error Report
                                                                    PRV-INT-001Provider NCPDP Interface Error Report.pdf
                                                                    Renaming pdf ...

                                                                    C:\temp>dir /B
                                                                    PRV-INT-001Provider NCPDP Interface Error Report.pdf
                                                                    test.xml

                                                                    C:\temp>


                                                                    srujana

                                                                    • Guest
                                                                    Re: Open and Reading the file
                                                                    « Reply #55 on: August 21, 2007, 03:11:45 AM »
                                                                    Hey! It finally worked vth VB :) thanks a ton......
                                                                    Shall try with batch program again....
                                                                    « Last Edit: August 21, 2007, 03:27:13 AM by srujana »

                                                                    srujana

                                                                    • Guest
                                                                    Re: Open and Reading the file
                                                                    « Reply #56 on: August 21, 2007, 03:41:22 AM »
                                                                    Delta,

                                                                      The batch program is working fine, in the sense the file is being moved to the destination but is not saved vth the desired name. Below is the output:

                                                                    C:\TEMP>set input=

                                                                    C:\TEMP>if not exist "*.xml" (
                                                                    echo No .xml files.
                                                                     pause  1>nul
                                                                     exit
                                                                    )

                                                                    C:\TEMP>for /F "usebackq delims=" %I in (`dir /b /a:-d /o:-d *.xml`) do (
                                                                    set input=%~nI
                                                                     goto out
                                                                    )

                                                                    C:\TEMP>(
                                                                    set input=test
                                                                     goto out
                                                                    )

                                                                    C:\TEMP>set output=

                                                                    C:\TEMP>for /F "usebackq tokens=4 delims='" %I in (`findstr /i "@name" "test.xml
                                                                    "`) do (
                                                                    set output=%I
                                                                     goto copy
                                                                    )

                                                                    C:\TEMP>set output==-

                                                                    C:\TEMP>echo output
                                                                    output

                                                                    C:\TEMP>copy "test.pdf" "C:\batch_output\=-.pdf"
                                                                            1 file(s) copied.

                                                                    C:\TEMP>pause
                                                                    Press any key to continue . . .

                                                                    C:\TEMP>cd \batch_output

                                                                    C:\batch_output>dir /b
                                                                    =-.pdf

                                                                    C:\batch_output>




                                                                    DeltaSlaya



                                                                      Apprentice
                                                                    • Google
                                                                      Re: Open and Reading the file
                                                                      « Reply #57 on: August 21, 2007, 05:00:27 AM »
                                                                      Ok in the findstr it should be "reportSearchPath". Its not even carrying out the commands in the for statement. This means that it's not finding that line in the xml document. I don't know why but it works fine for me and I don't see any problem with that code, I suggest you just use the VBS if it's working.

                                                                      The section that seems to not be working is this: (maybe you have copied it with the line wrap?)

                                                                      Quote
                                                                      for /F "usebackq tokens=4 delims='" %%I in (`findstr /i "reportSearchPath" "test.xml"`) do (
                                                                      set output=%%I
                                                                      goto copy
                                                                      )

                                                                      What that should do is perform the task: "FINDSTR /I "reportSearchPath" "test.xml"", which should output that line in that file.

                                                                      This is what I see when I do that on the file, could you try it just in a command line and see what it returns?

                                                                      Quote
                                                                      C:\Users\DeltaSlaya>FINDSTR /I "reportSearchPath" "test.xml"
                                                                        <reportSearchPath>/content/package[@name='Provider']/report[@name='PRV-INT-001:Provider NCPDP Interface Error Report']</reportSearchPath>

                                                                      C:\Users\DeltaSlaya>

                                                                      Try this code just by itself in batch also:

                                                                      Quote
                                                                      for /F "usebackq tokens=4 delims='" %%I in (`findstr /i "reportSearchPath" "test.xml"`) do (
                                                                      set output=%%I
                                                                      )
                                                                      echo *actual name found:* %output%
                                                                      pause

                                                                      For me the above example returns:

                                                                      Quote
                                                                      C:\Users\DeltaSlaya>for /F "usebackq tokens=4 delims='" %I in (`findstr /i "repo
                                                                      rtSearchPath" "test.xml"`) do (set output=%I )

                                                                      C:\Users\DeltaSlaya>(set output=PRV-INT-001:Provider NCPDP Interface Error Repor
                                                                      t )

                                                                      C:\Users\DeltaSlaya>echo *actual name found:* PRV-INT-001:Provider NCPDP Interfa
                                                                      ce Error Report
                                                                      *actual name found:* PRV-INT-001:Provider NCPDP Interface Error Report

                                                                      C:\Users\DeltaSlaya>pause
                                                                      Press any key to continue . . .

                                                                      Tell me what trying both those commands returns.
                                                                      System specs:
                                                                      Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                                      ASUS Striker Extreme
                                                                      XFX 8600GT XXX Edition
                                                                      2x 1gB Corsair XMS2 DDR2-800
                                                                      Seagate Barracuda 320gB SATA
                                                                      Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                                      -

                                                                      srujana

                                                                      • Guest
                                                                      Re: Open and Reading the file
                                                                      « Reply #58 on: August 21, 2007, 05:28:55 AM »
                                                                      Delta,

                                                                       This is the output:

                                                                      C:\TEMP>FINDSTR /I "reportSearchPath" "test.xml"
                                                                              <reportSearchPath>/content/package[@name=&apos;Provider&apos;]/report[@n
                                                                      ame=&apos;PRV-INT-001:Provider NCPDP Interface Error Report&apos;]</reportSearch
                                                                      Path>

                                                                      C:\TEMP>for /F "usebackq tokens=4 delims='" %%I in (`findstr /i "reportSearchPat
                                                                      h" "test.xml"`) do (
                                                                      %%I was unexpected at this time.

                                                                      C:\TEMP>set output=%%I

                                                                      C:\TEMP>)
                                                                      C:\TEMP>echo *actual name found:* %output%
                                                                      *actual name found:* %%I

                                                                      C:\TEMP>pause
                                                                      Press any key to continue . . .

                                                                      C:\TEMP>

                                                                      DeltaSlaya



                                                                        Apprentice
                                                                      • Google
                                                                        Re: Open and Reading the file
                                                                        « Reply #59 on: August 21, 2007, 05:51:21 AM »
                                                                        Ok it's performing the command alright.

                                                                        Could you please perform that second one in a batch file not in a command line, thanks.
                                                                        System specs:
                                                                        Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                                        ASUS Striker Extreme
                                                                        XFX 8600GT XXX Edition
                                                                        2x 1gB Corsair XMS2 DDR2-800
                                                                        Seagate Barracuda 320gB SATA
                                                                        Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                                        -

                                                                        srujana

                                                                        • Guest
                                                                        Re: Open and Reading the file
                                                                        « Reply #60 on: August 21, 2007, 06:01:54 AM »
                                                                        Hi,
                                                                         I just tried the second line in the batch file. Find the output below:

                                                                         C:\TEMP>sample.bat

                                                                        C:\TEMP>for /F "usebackq tokens=4 delims='" %I in (`findstr /i "reportSearchPath
                                                                        " "test.xml"`) do (set output=%I )

                                                                        C:\TEMP>echo *actual name found:* %%I
                                                                        *actual name found:* %%I

                                                                        C:\TEMP>pause
                                                                        Press any key to continue . . .

                                                                        C:\TEMP>


                                                                        DeltaSlaya



                                                                          Apprentice
                                                                        • Google
                                                                          Re: Open and Reading the file
                                                                          « Reply #61 on: August 21, 2007, 06:05:08 AM »
                                                                          ...

                                                                          Sorry to confuse you but could you run that batch file with the example xml you supplied in the same folder...
                                                                          System specs:
                                                                          Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                                          ASUS Striker Extreme
                                                                          XFX 8600GT XXX Edition
                                                                          2x 1gB Corsair XMS2 DDR2-800
                                                                          Seagate Barracuda 320gB SATA
                                                                          Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                                          -

                                                                          srujana

                                                                          • Guest
                                                                          Re: Open and Reading the file
                                                                          « Reply #62 on: August 21, 2007, 06:49:48 AM »
                                                                          I ran the batch file with only the second statement in the same folder as the XML file.

                                                                          DeltaSlaya



                                                                            Apprentice
                                                                          • Google
                                                                            Re: Open and Reading the file
                                                                            « Reply #63 on: August 21, 2007, 07:00:44 AM »
                                                                            With the xml file called test.txt? See I don't know why that's not working sorry, logically it should and it does for me.
                                                                            System specs:
                                                                            Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                                            ASUS Striker Extreme
                                                                            XFX 8600GT XXX Edition
                                                                            2x 1gB Corsair XMS2 DDR2-800
                                                                            Seagate Barracuda 320gB SATA
                                                                            Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                                            -

                                                                            srujana

                                                                            • Guest
                                                                            Re: Open and Reading the file
                                                                            « Reply #64 on: August 21, 2007, 10:17:52 PM »
                                                                            The xml file is test.xml and not test.txt. It has to be saved as ".xml" Am trying with the same, but no result :(

                                                                            DeltaSlaya



                                                                              Apprentice
                                                                            • Google
                                                                              Re: Open and Reading the file
                                                                              « Reply #65 on: August 21, 2007, 10:51:46 PM »
                                                                              I meant test.xml, sorry. Looks like you'll have to go with the VBS for now, unless someone more expert than me in  Batch can figure it out?

                                                                              Ghostdog, have you tried my script? Does it work for you?
                                                                              System specs:
                                                                              Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                                              ASUS Striker Extreme
                                                                              XFX 8600GT XXX Edition
                                                                              2x 1gB Corsair XMS2 DDR2-800
                                                                              Seagate Barracuda 320gB SATA
                                                                              Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                                              -

                                                                              ghostdog74



                                                                                Specialist

                                                                                Thanked: 27
                                                                                Re: Open and Reading the file
                                                                                « Reply #66 on: August 21, 2007, 11:37:36 PM »
                                                                                Ghostdog, have you tried my script? Does it work for you?
                                                                                no, have not. can u post your latest version of the batch, and the format of the xml you have.

                                                                                DeltaSlaya



                                                                                  Apprentice
                                                                                • Google
                                                                                  Re: Open and Reading the file
                                                                                  « Reply #67 on: August 22, 2007, 12:27:04 AM »
                                                                                  Heres the latest code, I believe:

                                                                                  Quote
                                                                                  @echo off

                                                                                  :: Change "C:\OUTPUT" to output directory with NO "\" at end.
                                                                                  set outdir=C:\OUTPUT
                                                                                  if not exist "%outdir%" (
                                                                                     echo Output folder not exist.
                                                                                     pause >nul
                                                                                     exit
                                                                                  )

                                                                                  :: Change "C:\" to input directory with "\" at end.
                                                                                  cd C:\


                                                                                  set input=

                                                                                  :: Check for xmls
                                                                                  if not exist "*.xml" (
                                                                                     echo No .xml files.
                                                                                     pause >nul
                                                                                     exit
                                                                                  )

                                                                                  :: Set input to last modified .xml in dir
                                                                                  for /f "usebackq delims=" %%I in (`dir /b /a:-d /o:-d "*.xml"`) do (
                                                                                     set input=%%~nI
                                                                                     goto out
                                                                                  )

                                                                                  :out

                                                                                  :: Grab 'actual' name of pdf from xml
                                                                                  set output=

                                                                                  for /f "usebackq tokens=4 delims='" %%I in (`findstr /i "reportSearchPath" "%input%.xml"`) do (
                                                                                     set output=%%I
                                                                                     goto copy
                                                                                  )

                                                                                  :copy
                                                                                  set output=%output::=-%
                                                                                  copy "%input%.pdf" "%outdir%\%output%.pdf"
                                                                                  pause

                                                                                  And the .xml file

                                                                                  Quote
                                                                                  <?xml version="1.0" encoding="utf-8" ?>
                                                                                  - <!--   Copyright (C) 2006 Cognos Incorporated.  All Rights Reserved.
                                                                                    Cognos (R) is a trademark of Cognos Incorporated.

                                                                                    -->
                                                                                  - <!--   Experimental.
                                                                                    Product features described in this file may not be supported in future releases.

                                                                                    -->
                                                                                  - <outputDescriptor xmlns="http://developer.cognos.com/schema/OutputDescriptor/1.0" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
                                                                                    <asOfTime>2007-08-12T13:38:08.093Z</asOfTime>
                                                                                    <burstKey />
                                                                                    <contact />
                                                                                    <defaultDescription />
                                                                                    <defaultName>2007-08-12T13:38:09.078Z</defaultName>
                                                                                    <fileName>1376_1186940289078.pdf</fileName>
                                                                                    <locale>en-us</locale>
                                                                                    <owner>rgajendra</owner>
                                                                                    <ownerNamespace>COGNOS-DEV Team</ownerNamespace>
                                                                                    <parameterValues />
                                                                                    <reportSearchPath>/content/package[@name='Provider']/report[@name='PRV-INT-001:Provider NCPDP Interface Error Report']</reportSearchPath>
                                                                                    <reportViewSearchPath>/content/folder[@name='COGNOS-DEV Team']/reportView[@name='Report View of PRV-INT-001:Provider NCPDP Interface Error Report']</reportViewSearchPath>
                                                                                    </outputDescriptor>

                                                                                  You will also need a .pdf file of the same name in the xml's directory. The variables to set are clearly defined.
                                                                                  Also could the OP please try that again, I noticed that it wasn't working because it was looking in extension not the file name?
                                                                                  System specs:
                                                                                  Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                                                  ASUS Striker Extreme
                                                                                  XFX 8600GT XXX Edition
                                                                                  2x 1gB Corsair XMS2 DDR2-800
                                                                                  Seagate Barracuda 320gB SATA
                                                                                  Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                                                  -

                                                                                  ghostdog74



                                                                                    Specialist

                                                                                    Thanked: 27
                                                                                    Re: Open and Reading the file
                                                                                    « Reply #68 on: August 22, 2007, 12:49:30 AM »
                                                                                    well, i think it does work.
                                                                                    Code: [Select]
                                                                                    C:\temp>dir /B
                                                                                    test.pdf
                                                                                    test.xml
                                                                                    test1.pdf
                                                                                    test1.xml

                                                                                    C:\temp>cd ..

                                                                                    C:\>test.bat
                                                                                            1 file(s) copied.
                                                                                    Press any key to continue . . .
                                                                                    C:\temp>dir /B
                                                                                    PRV-INT-001-Provider NCPDP Interface Error Report 2.pdf
                                                                                    test.pdf
                                                                                    test.xml
                                                                                    test1.pdf
                                                                                    test1.xml

                                                                                    however, only for 1 file. Needs extra for loops to iterate multiple xml files(or maybe not, by OP's requirements)..however that's another story.

                                                                                    DeltaSlaya



                                                                                      Apprentice
                                                                                    • Google
                                                                                      Re: Open and Reading the file
                                                                                      « Reply #69 on: August 22, 2007, 12:52:09 AM »
                                                                                      Well he said the most recent, thats what it does, yet for some reason does not do anything for them. I still believe on their end they entered something wrong or changed something. They should try the above, by itself with the right things changed and all the correct files and dirs present.
                                                                                      System specs:
                                                                                      Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                                                      ASUS Striker Extreme
                                                                                      XFX 8600GT XXX Edition
                                                                                      2x 1gB Corsair XMS2 DDR2-800
                                                                                      Seagate Barracuda 320gB SATA
                                                                                      Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                                                      -

                                                                                      DeltaSlaya



                                                                                        Apprentice
                                                                                      • Google
                                                                                        Re: Open and Reading the file
                                                                                        « Reply #70 on: August 22, 2007, 01:33:24 AM »
                                                                                        Honestly, if the OP hasn't got my code working then there's no real point anyway. They said it would be run after each time the files have been created.

                                                                                        Anyway, how I would have done it, using skip=. I'm just wondering why does skip=0 not work? It just skips the 0, I guess if skip is defined then you can't perform a command on the first line..
                                                                                        System specs:
                                                                                        Intel Core 2 Duo E6600 (up to 3.3 stock V and air)
                                                                                        ASUS Striker Extreme
                                                                                        XFX 8600GT XXX Edition
                                                                                        2x 1gB Corsair XMS2 DDR2-800
                                                                                        Seagate Barracuda 320gB SATA
                                                                                        Raidmax Ninja 918 (520W ATXV2.0 PSU)
                                                                                        -

                                                                                        srujana

                                                                                        • Guest
                                                                                        Re: Open and Reading the file
                                                                                        « Reply #71 on: August 22, 2007, 04:02:22 AM »
                                                                                        Ghostdog,

                                                                                          I ran the script with two files in the src folder. But, its moving only the 1st file and not the second one. Below is the output:

                                                                                        C:\vbscript>vb_batch.bat

                                                                                        C:\vbscript>CD C:\vbscript

                                                                                        C:\vbscript>cscript /nologo vb_script.vbs
                                                                                        found  PRV-INT-001 PRV-INT-001
                                                                                        The string to replace is  PRV-INT-001-Provider NCPDP Interface Error Report
                                                                                        PRV-INT-001-Provider NCPDP Interface Error Report.pdf
                                                                                        Renaming pdf ...
                                                                                        found  PRV-INT-002 PRV-INT-002
                                                                                        C:\vbscript>


                                                                                        ghostdog74



                                                                                          Specialist

                                                                                          Thanked: 27
                                                                                          Re: Open and Reading the file
                                                                                          « Reply #72 on: August 22, 2007, 05:38:12 AM »
                                                                                          here's a modification
                                                                                          Code: [Select]
                                                                                          Dim objFSO,objFile,objRE,colMatches,oMatches
                                                                                          Dim myFiles, srcFolder, dstFolder,dstFile,line,strToFind,strFileName
                                                                                          Dim pdfBase,xmlBase,i,strContents
                                                                                          Dim pdfStore(),pdfFullStore() 'define some array to store paths
                                                                                          Set objFSO = CreateObject("Scripting.FileSystemObject")
                                                                                          srcFolder="c:\temp" 'Server source folder location
                                                                                          dstFolder="c:\temp" 'Destination Folder as desired
                                                                                          i=0 'array counter
                                                                                          For 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
                                                                                          Next
                                                                                          For 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)
                                                                                          strToFind = getString(myFiles)
                                                                                          dstFile = strToFind&".pdf"
                                                                                          objFSO.MoveFile pdfFullStore(i),dstFolder&"\"&dstFile
                                                                                          End If
                                                                                          Next
                                                                                          End If
                                                                                          Next

                                                                                          Function getString(theFile)
                                                                                          Set objRE = New RegExp
                                                                                          objRE.Global     = True
                                                                                          objRE.IgnoreCase = False
                                                                                          objRE.Pattern   = "<reportSearchPath>.*/report\[@name='(.*?)'\]</reportSearchPath>"
                                                                                          Set objFile=objFSO.OpenTextFile(theFile,1)
                                                                                          strContents=objFile.ReadAll
                                                                                          Set Matches = objRE.Execute(strContents)
                                                                                          For Each match In Matches
                                                                                          For Each smatch In match.Submatches
                                                                                          result=Replace(smatch,":"," ")
                                                                                          Next
                                                                                          Next
                                                                                          getString = result
                                                                                          End Function

                                                                                          output:
                                                                                          Code: [Select]
                                                                                          C:\vbscript>dir c:\temp /B
                                                                                          test.pdf
                                                                                          test.xml
                                                                                          test1.pdf
                                                                                          test1.xml

                                                                                          C:\vbscript>cscript /nologo MoveCogNosReports2.vbs
                                                                                          found  test test
                                                                                          found  test1 test1

                                                                                          C:\vbscript>dir c:\temp /B
                                                                                          PRV-INT-001 Provider NCPDP Interface Error Report.pdf
                                                                                          PRV-INT-002 Provider NCPDP Interface Error Report.pdf
                                                                                          test.xml
                                                                                          test1.xml


                                                                                          srujana

                                                                                          • Guest
                                                                                          Re: Open and Reading the file
                                                                                          « Reply #73 on: August 22, 2007, 05:57:30 AM »
                                                                                          Hey! Tx... but am able to use the previous script. Vl run this script and let u know in case of ne issues :)