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

Author Topic: skip specific folder in FOR Command  (Read 10153 times)

0 Members and 1 Guest are viewing this topic.

novice84

    Topic Starter


    Rookie

    • Experience: Beginner
    • OS: Windows 7
    skip specific folder in FOR Command
    « on: July 01, 2013, 07:14:02 AM »
    DIR command works fine to show all folders list except with/having name "noneed"

    Code: [Select]
    dir /b /a:d | find /v "noneed"
    in FOR command it works to search all as shown below :

    Code: [Select]
    for /f "delims=" %%B in ('dir /b /a:d') do
    but if put it in FOR command it doesn't work if we change to

    Code: [Select]
    for /f "delims=" %%B in ('dir /b /a:d  | find /v "noneed" ') do
    how we can skip specific folders in FOR command

    Salmon Trout

    • Guest
    Re: skip specific folder in FOR Command
    « Reply #1 on: July 01, 2013, 07:25:06 AM »
    When you are using certain special characters in a FOR dataset you need to "escape" them. The pipe symbol | is one of these and you need to escape it with a caret ^ like this

    for /f "delims=" %%B in ('dir /b /a:d  ^| find /v "noneed" ') do

    novice84

      Topic Starter


      Rookie

      • Experience: Beginner
      • OS: Windows 7
      Re: skip specific folder in FOR Command
      « Reply #2 on: July 01, 2013, 07:43:31 AM »
       :D thanks Salmon
      if you can please explain this ^ character and function in batch file it will be very helpful

      Salmon Trout

      • Guest
      Re: skip specific folder in FOR Command
      « Reply #3 on: July 01, 2013, 07:50:11 AM »

      novice84

        Topic Starter


        Rookie

        • Experience: Beginner
        • OS: Windows 7
        Re: skip specific folder in FOR Command
        « Reply #4 on: July 01, 2013, 08:08:03 AM »
        thanks Salmon link gives good explanation
        I am just beginner with basic Computer knowledge, so short explanation not enough to understand.

        one more Q. this single loop of FOR I am using, any other command I put underneath goes into loop
        how we can mention in batch file to start other command after finishing one loop and then next & next...

        May be I am not able to explain properly what I want but I hope you some other link to make me understand better. ???

        Salmon Trout

        • Guest
        Re: skip specific folder in FOR Command
        « Reply #5 on: July 01, 2013, 08:41:48 AM »
        one more Q. this single loop of FOR I am using, any other command I put underneath goes into loop

        How are you writing the loop? Please give an example of code that behaves as you describe.

        novice84

          Topic Starter


          Rookie

          • Experience: Beginner
          • OS: Windows 7
          Re: skip specific folder in FOR Command
          « Reply #6 on: July 02, 2013, 01:54:05 AM »
           :-[ :-[ :-[ :-[
          I thought if any code is doing repeated job is loop.
          lilttle embarrassed...... my poor knowledge..... :( :( :( :(
          what we will call this ?

          anyway, code I am using to is to rename multiple files (from other forum post)
          Code: [Select]
          ren "%~1" "%name%"
          and under that line if I put in next line

          Code: [Select]
          move C:\folder\*.txt C:\folder2it moves all files before naming

          I want to move few files altogether to one folder after renaming all
          and display some msg thru echo screen while this FOR LOOP or say FOR command is running

          foxidrive



            Specialist
          • Thanked: 268
          • Experience: Experienced
          • OS: Windows 8
          Re: skip specific folder in FOR Command
          « Reply #7 on: July 02, 2013, 07:05:59 AM »
          If you are putting it under the other command then you probably want to move each file as it is renamed:

          Code: [Select]
          move "%~dp1\%name%" "C:\folder2"

          novice84

            Topic Starter


            Rookie

            • Experience: Beginner
            • OS: Windows 7
            Re: skip specific folder in FOR Command
            « Reply #8 on: July 02, 2013, 07:41:51 AM »
            what if I want to move after finishing complete rename, moving few files not all, some at different place.
            and if want to start some other command not related to first task how we can start after finishing first one.
            what command/code we have to put in in-between two codes of FOR LOOP or FOR commands
            e.g. if want to display msg using echo and pause or open a folder, this interfere with rename process if we put at end of code

            foxidrive



              Specialist
            • Thanked: 268
            • Experience: Experienced
            • OS: Windows 8
            Re: skip specific folder in FOR Command
            « Reply #9 on: July 02, 2013, 07:59:21 AM »
            Shows us your code and then ask your question.

            novice84

              Topic Starter


              Rookie

              • Experience: Beginner
              • OS: Windows 7
              Re: skip specific folder in FOR Command
              « Reply #10 on: July 03, 2013, 07:46:27 AM »
               ???
              thankfully I got code from you Foxidrive from other forum batch rename
              may be you help people in so many fourms so you don't remember.
              anyway,  I am just putting move command under the code you made
              like this
              move C:\test\*.txt C:\test2\text-files
              move C:\test\*.doc C:\test2\DOC-files

              what I want is just to separate both process. After renaming it should do next step.

              other thing is just my curiosity. say if I am doing rename and moving and it is taking 10-15 seconds, instead blinking or showing move files messages, on screen can we display msg with echo
              Renaming & Sorting Files please wait.....


              foxidrive



                Specialist
              • Thanked: 268
              • Experience: Experienced
              • OS: Windows 8
              Re: skip specific folder in FOR Command
              « Reply #11 on: July 03, 2013, 09:08:26 AM »
              It's not surprising that I forget all the people I've written code for - a lot don't ever reply so it's like my posts go into a black hole.

              I don't follow your questions though as we need to see the code to follow what you are referring to.

              You can always put this before the process - it won't change the code.
              echo Renaming & Sorting Files please wait.....

              novice84

                Topic Starter


                Rookie

                • Experience: Beginner
                • OS: Windows 7
                Re: skip specific folder in FOR Command
                « Reply #12 on: July 04, 2013, 06:06:42 AM »
                got it right... 8) I was putting echo at wrong place.
                here is the code...
                Code: [Select]
                @echo off
                pushd "C:\test\folder"
                for /f "delims=" %%a in ('dir /b /a-d * ') do call :next "%%a"
                popd
                pause
                goto :eof
                :next
                set "name=%~nx1"
                set "name=%name:old=old01%"
                ren "%~1" "%name%"
                « Last Edit: July 04, 2013, 06:42:23 AM by novice84 »

                novice84

                  Topic Starter


                  Rookie

                  • Experience: Beginner
                  • OS: Windows 7
                  Re: skip specific folder in FOR Command
                  « Reply #13 on: July 04, 2013, 07:30:54 AM »
                  I fixed it. :D
                  thanks Foxidrive, your tip was good.
                  I was also putting move command lines at wrong position.

                  1. but still question remains what if I put any other FOR command or any other command under this code for some different purpose, will it work ? & how it will work ? how separate next code from this.

                  2. what we will call this FOR command ? isn't it a loop ?

                  3. another question what is
                  Code: [Select]
                  goto :eofin the code. Even if I remove it, doesn't make any difference!!!!!???

                  thanks for your guidance in advance
                  It's not surprising that I forget all the people I've written code for - a lot don't ever reply so it's like my posts go into a black hole.


                   :o I did replied and thanked you. You are doing great help (a good karma). Saved a lot of time for me. I assure you, It's not going into black hole.
                  « Last Edit: July 04, 2013, 08:23:30 AM by novice84 »

                  Lemonilla



                    Apprentice

                  • "Too sweet"
                  • Thanked: 70
                  • Computer: Specs
                  • Experience: Experienced
                  • OS: Windows 7
                  Re: skip specific folder in FOR Command
                  « Reply #14 on: July 04, 2013, 09:20:14 AM »
                  1) Currently any other command added to the bottom will also be run during the "for loop".

                  2) It is a "for loop".

                  3) 'goto :eof' tells it to return to the place in the code it was before being called. currently it is not doing anything because it is not below a flag/label.  if you were to move it to the bottom, it would bounce back to inside the for loop after all commands were executed when you use 'call :next'.



                  Quick question of my own (more addressed to others on the board), why would you not write it all in one place.
                  Code: [Select]
                  setlocal EnableDelayedExpansion
                  for /f "delims=" %%A in ('dir /b /a-d * ') do (
                  set "name=%%~nxA"
                  set "name=!name:old=old01!"
                  ren "%%~A" "!name!"
                  )
                  Is there any differences, or is it just a stylistic thing?
                  Quote from: patio
                  God Bless the DOS Helpers...
                  Quote
                  If it compiles, send the files.