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

Author Topic: Batch for comparing values  (Read 10309 times)

0 Members and 1 Guest are viewing this topic.

foxidrive



    Specialist
  • Thanked: 268
  • Experience: Experienced
  • OS: Windows 8
Re: Batch for comparing values
« Reply #15 on: April 18, 2014, 01:12:47 AM »
This batch not working it copy only itself to folder test\new
that also is not ok because there must be only one file

I runned this from \login folder where batch file should be

hehe  It's working fine.  The batch file is the newest file. :D

Try this:

Code: [Select]
@echo off
for /f "delims=" %%a in ('dir /b /od /a-d ^|find /v /i "%~nx0" ') do set "lastest_file=%%a"
copy "%lastest_file%" "..\test\new"

Blisk

    Topic Starter


    Intermediate

    Thanked: 1
    • Experience: Familiar
    • OS: Windows 7
    Re: Batch for comparing values
    « Reply #16 on: April 22, 2014, 12:49:26 AM »
    no still not working I think problem is because bat file is in another parallel folder of test folder
    and still copys bat file within this bat file not a log file in paralel folder.

    Squashman



      Specialist
    • Thanked: 134
    • Experience: Experienced
    • OS: Other
    Re: Batch for comparing values
    « Reply #17 on: April 22, 2014, 04:40:40 AM »
    are you using this code within some larger batch file?

    Blisk

      Topic Starter


      Intermediate

      Thanked: 1
      • Experience: Familiar
      • OS: Windows 7
      Re: Batch for comparing values
      « Reply #18 on: April 22, 2014, 04:47:20 AM »
      are you using this code within some larger batch file?

      no 2 batch files are in that folder.
      one is above second is this

      Code: [Select]
      robocopy \\myserver\myfodler\Drivers\conf\log \\myserver\myfodler\Drivers\conf\log\chk /MIR /W:5
      exit

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: Batch for comparing values
      « Reply #19 on: April 22, 2014, 06:36:41 AM »
      I would have assumed as Foxidrive has that you were combining all the code into one batch file.  So basically again, one of your batch files is your newest file so that is the file it is using.  You will probably have to change the code to something like this.

      Code: [Select]
      @echo off
      for /f "delims=" %%a in ('dir /b /od /a-d ^|findstr /V /I  /C:"*.bat" ') do set "lastest_file=%%a"
      copy "%lastest_file%" "..\test\new"

      foxidrive



        Specialist
      • Thanked: 268
      • Experience: Experienced
      • OS: Windows 8
      Re: Batch for comparing values
      « Reply #20 on: April 22, 2014, 10:36:57 AM »
      That should work without the *

      I just amused myself with the switches in this one:

      Code: [Select]
      @echo off
      for /f "delims=" %%a in ('dir /b /od /a-d ^|findstr /e /v /i /L ".bat" ') do set "lastest_file=%%a"
      copy "%lastest_file%" "..\test\new"

      Squashman



        Specialist
      • Thanked: 134
      • Experience: Experienced
      • OS: Other
      Re: Batch for comparing values
      « Reply #21 on: April 22, 2014, 11:03:59 AM »
      I just amused myself with the switches in this one:
        :rofl: >>:

      Blisk

        Topic Starter


        Intermediate

        Thanked: 1
        • Experience: Familiar
        • OS: Windows 7
        Re: Batch for comparing values
        « Reply #22 on: April 23, 2014, 12:36:18 AM »
        It works but only if I run from the same folder where that newest file is, if I run from this folder where batch should be, than it not working
        c:\users\mike\software\screener\database\database2014\office\login

        I also notice that sometimes it copy temporary file tmpcopy.log which its maded in some errors, how to exclude to exclude that two files which start with tmp?
        tmpcopy.log and tmpfile.txt
        « Last Edit: April 23, 2014, 12:47:26 AM by Blisk »

        foxidrive



          Specialist
        • Thanked: 268
        • Experience: Experienced
        • OS: Windows 8
        Re: Batch for comparing values
        « Reply #23 on: April 23, 2014, 01:34:26 AM »
        This is a situation where better information about the task would have helped.

        As it stands you got code that gives you the newest file, and that is all you asked for.
        What files are you checking, for example?

        Blisk

          Topic Starter


          Intermediate

          Thanked: 1
          • Experience: Familiar
          • OS: Windows 7
          Re: Batch for comparing values
          « Reply #24 on: April 23, 2014, 01:45:13 AM »
          they are log files of succesfully copied files drom disk A o disk B.
          If error happends than two extra log files are maded, I forgot for those two as it happends really rare.

          I need latest log file to be copied to folder new so some people can check that log file if they need it, which ahve almost none of compuer skills

          foxidrive



            Specialist
          • Thanked: 268
          • Experience: Experienced
          • OS: Windows 8
          Re: Batch for comparing values
          « Reply #25 on: April 23, 2014, 02:21:43 AM »
          Add *.log after the dir command and it will only process .log files.

          You can also use the pushd command to make the log folder the working directory.

          Code: [Select]
          @echo off
          pushd "folder\with\log\files"
          for /f "delims=" %%a in ('dir *.log /b /od /a-d ') do set "lastest_file=%%a"
          copy "%lastest_file%" "..\test\new"
          popd

          Blisk

            Topic Starter


            Intermediate

            Thanked: 1
            • Experience: Familiar
            • OS: Windows 7
            Re: Batch for comparing values
            « Reply #26 on: April 23, 2014, 04:15:16 AM »
            if it is possible withouth that full path of log files I really appreciate that.
            Because I need to make differend batch file for every user I have
            fro example what i mean.

            c:\users\MIKE\software\screener\database\database2014\office\logfiles\monday.txt

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: Batch for comparing values
            « Reply #27 on: April 23, 2014, 05:23:16 AM »
            With this batch in the login folder then you can use a relative path to the logfiles folder.


            Code: [Select]
            @echo off
            pushd "..\logfiles"
            for /f "delims=" %%a in ('dir /b /od /a-d ') do set "lastest_file=%%a"
            copy "%lastest_file%" "..\test\new"
            popd

            Salmon Trout

            • Guest
            Re: Batch for comparing values
            « Reply #28 on: April 23, 2014, 05:47:02 AM »
            if it is possible withouth that full path of log files I really appreciate that.
            Because I need to make differend batch file for every user I have
            fro example what i mean.

            c:\users\MIKE\software\screener\database\database2014\office\logfiles\monday.txt

            Check out the %username% system variable


            Blisk

              Topic Starter


              Intermediate

              Thanked: 1
              • Experience: Familiar
              • OS: Windows 7
              Re: Batch for comparing values
              « Reply #29 on: April 23, 2014, 05:48:23 AM »
               foxidrive
              you are the best, this really works, thank you. :D



              Salmon Trout
              I know about  %username%  but it doesn't work if user is not logged in.