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

Author Topic: Capture multiple selected File Names in Text File  (Read 3915 times)

0 Members and 1 Guest are viewing this topic.

sjSAS

    Topic Starter


    Starter

    Capture multiple selected File Names in Text File
    « on: June 02, 2008, 08:46:33 AM »
    Hi All,

     I am trying to develop one utility where in I want to capture names of multiple selected files  in windwos explorer using context menu I am able to capture file names into text file but I want to add one extra command for post processing which is repeating for every selected file. For eg.: If i select 10 files, this post-processing command is repeated 9 times. Below is my code, please help me correct it. Thanks!

    :TOP
         IF "%1"=="" GOTO END
         ::ECHO %saspath% -sysin %1 %options% >> names.txt
         echo %1 >>names.txt
         SHIFT
         GOTO TOP

    :END
     echo %saspath% -sysin F:\share\Manohar\pgm\chklog_asg.sas %options% >> names.txt


    I want the END portion to be executed ONLY ONCE and after I capture names of all files but its repeating n-1 times where n is number of selected files.

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: Capture multiple selected File Names in Text File
    « Reply #1 on: June 02, 2008, 11:59:05 AM »
    Batch code is designed to run in the shell environment. There is nothing wrong with your logic when it gets the command line arguments from the command line, however something may be getting lost in the handover from the Windows environment to the shell.

    Quote
    For eg.: If i select 10 files, this post-processing command is repeated 9 times.

    Is this always true? For instance if you select 5 files, do only 4 get passed? Seems odd that it would stop working when the parameters are no longer addressable. If that's true then this piece of code won't help, but hey you never know!


    Code: [Select]
    @echo off
    for /f "tokens=* delims=" %%v in ("%*") do (
    set str=%%v
    )
    set /a count=1
    :top
    for /f "tokens=%count%" %%v in ("%str%") do (
    echo %%v >> names.txt
    call set /a count=%%count%%+1
    goto top
    )
    :out
    echo %saspath% -sysin F:\share\Manohar\pgm\chklog_asg.sas %options% >> names.txt

    Perhaps to can give us more info on how this batch file is connected to explorer and what prompts it's execution.

     8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein

    sjSAS

      Topic Starter


      Starter

      Re: Capture multiple selected File Names in Text File
      « Reply #2 on: June 02, 2008, 12:27:02 PM »
      Hi,

        Thanks! for your reply. But the issue still exists. To give you idea about how this batch file is executed,  I went to Tools->Folder Options->File Types->.sas( SAS Program) -> Advance -> ChkLog(menu item)

      I have following command pasted : F:\Share\Manohar\copy.bat "%1" in action perfomed box.

      What I basically want to do is get names of selected .sas programs, execute them and check their log files. When I run your code below is the output I am getting
      "F:\Share\manohar\v_adhy.sas"
      "C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
      "F:\Share\manohar\v_adfb.sas"
      "C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
      "F:\Share\manohar\v_adfh.sas"
      "C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
      "F:\Share\manohar\v_adhb_29feb.sas"
      "C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
      "F:\Share\manohar\v_adhb_sure.sas"
      "C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon

      You can see that chklog_asg.sas program is selected multiple times. All I want is to be selected once and that too at the end. Is it has to do with %1 parameter which I pass in action performed box. I even tried to remove that %1 but windows by defualt enter it again. Please provide your input. Thanks!

      Sidewinder



        Guru

        Thanked: 139
      • Experience: Familiar
      • OS: Windows 10
      Re: Capture multiple selected File Names in Text File
      « Reply #3 on: June 02, 2008, 01:26:47 PM »
      I seem to remember to something a similar way back. For some reason the "%L" variable was used on the command line in Windows.

      Try using open in the action box and in the application used to perform action box use "F:\Share\Manohar\copy.bat" "%L". And make sure the DDE box is checked.

      Seems the %L is a system variable used in Windows Explorer.

       8)
      The true sign of intelligence is not knowledge but imagination.

      -- Albert Einstein

      sjSAS

        Topic Starter


        Starter

        Re: Capture multiple selected File Names in Text File
        « Reply #4 on: June 02, 2008, 01:48:55 PM »
        Hi,

          Thanks! again for your reply. But no LUCK. It still executes the :out code n number of times. The output still is:

        "F:\Share\manohar\v_adhb_29feb.sas"
        "C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
        "F:\Share\manohar\v_adfb.sas"
        "C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon
        "F:\Share\manohar\v_adfh.sas"
        "C:\Program Files\SAS\SAS 9.1\sas.exe" -sysin F:\share\Manohar\pgm\chklog_asg.sas -nosplash -icon


        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: Capture multiple selected File Names in Text File
        « Reply #5 on: June 02, 2008, 02:46:24 PM »
        Not sure which batch file you're using. (yours or mine posted earlier). In any case add a pause statement at the end, make sure echo is off, and post the console listing.

        Something does not make sense; if each file selected is run thru a batch file separately, there should be n number of post processing commands, not n-1. If the files are submitted to the batch file as a group then I can find not an error in your original logic. Maybe the console list will give us some insight.

         8)
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein