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

0 Members and 1 Guest are viewing this topic.

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