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 38795 times)

0 Members and 1 Guest are viewing this topic.

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 :)