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

Author Topic: Searching for files within subdirectories  (Read 8386 times)

0 Members and 1 Guest are viewing this topic.

Grimbear13

    Topic Starter


    Rookie

    Searching for files within subdirectories
    « on: February 03, 2010, 07:21:56 AM »
    Sorry, this probably has been answered before but,

    I'm trying to take a list of files that are potentially in a file, read the file and then search through a folder and all subdirectories for the files in the list.  I know how to read the list, however I do not know how to make it search all subdirectories without mapping each directory within its own nested for loop.

    Also then conversely I want to search all files in the directories and subdirectories and have them checked off against the list to make sure there are not any extra files in the folders.

    If someone could show me the command for subdirectory searching or an example of it I could probably figure out how to make both of these processes work.

    EDIT:  Something to take into consideration, these folders may have spaces in them and I do not have the power to rename said folders.  They are given to me to check, I'm not sure if this will be an issue when doing a nested for to check through but figured I'd bring it up now as opposed to after I get a potential answer only to have it blow up due to the space int he folder name.

    Grimbear13

      Topic Starter


      Rookie

      Re: Searching for files within subdirectories
      « Reply #1 on: February 03, 2010, 08:35:51 AM »
      Okay through some reasearch I found out how to use both "tokens=*" which would handle the spaces issue, and then I found the /R switch for the for loop but no matter how I try to use it it's always crashing.  Can someone provide an example similar to this:

      Code: [Select]
      for /F "tokens=*" %%I in (inlist) do (

      for /R "tokens=*" %%J in (*) do (
      if %%I==%%J (echo %%I CHECK >> Results.txt)
      )

      echo %%I MISSING >> Results.txt
      )

      BillRichardson



        Intermediate

        Thanked: 15
        Re: Searching for files within subdirectories
        « Reply #2 on: February 03, 2010, 10:08:07 AM »
        C:\>dir /s /b *.pdf  >  pdffiles.txt

        C:\>


        C:\>dir /s *.pdf
         
         Volume Serial Number is F4A3-D6B3

         Directory of C:\bin\doc\gawk\3.1.6\gawk-3.1.6

        12/29/2007  02:48 AM         2,058,611 gawk.pdf
                       1 File(s)      2,058,611 bytes

         Directory of C:\bin\doc\gawk\UnixV7

        07/29/2007  07:07 AM            28,217 awk_V7.1.pdf
        07/29/2007  05:41 AM            60,796 awk_V7.pdf
                       2 File(s)         89,013 bytes

         Directory of C:\bin\man\pdf

        12/28/2007  03:45 PM           315,094 gawk-man.pdf
                       1 File(s)        315,094 bytes

         Directory of C:\DELL\Docs\manual

        09/10/2007  03:44 PM        13,980,991 eom.pdf
                       1 File(s)     13,980,991 bytes
        .
        .
        .
        Bill Richardson

        Grimbear13

          Topic Starter


          Rookie

          Re: Searching for files within subdirectories
          « Reply #3 on: February 03, 2010, 11:26:23 AM »
          Thanks for the reply, but I'm not looking to see subdirectories.  I need to know how to execute commands through all subdirectories.  dir shows what subdirectories are there, but I need to be able to compare the names of all files in sub directories to the name of the file in the list.

          This is the full code that I've worked out thus far

          Code: [Select]
          ::@echo off > debug.txt
          color 0A
          ::The preceding line turns off screen printing and sets the text color to Bright Green.

          ::Created by Scott Dean

          for /F "tokens=*" %%I in (inlist) do (
          Call :ResetBool
          set filename=%%I

          for %%J in (*) do (
          set file=%%J
          Call :ValidCheck
          )
          )
          Call :Print
          Call :MissingCheck
          pause
          )
          GoTo :EOF

          :ValidCheck
          if %filename%==%file% (Goto :CheckPrint)
          GoTo :EOF

          :MissingCheck
          if %bool%==false (GoTo :MissingPrint)
          GoTo :EOF

          :CheckPrint
          echo %filename% CHECK >> Results.txt
          set bool=true
          GoTo :EOF

          :MissingPrint
          echo %filename% MISSING >> Results.txt
          GoTo :EOF

          :ResetBool
          set bool=false
          GoTo :EOF

          :Print
          echo %filename% >> lol.txt
          echo %bool% >> rofl.txt
          GoTo :EOF

          I have one of the files listed in the inlist in the directory and that gives an appropriate response in the Results.txt.  However it seems like nothing after the ValidCheck in the nested loop executes.  I figured it has something to do w/ me sending it to the end of file, but when I remove that it will execute down all of those other regions as well.  I even tried to put new regions within the loops to send it back to specific areas after execution however it bombs before it even does anything if you put regions within the for's.

          Thanks,
          « Last Edit: February 03, 2010, 11:41:31 AM by Grimbear13 »

          BillRichardson



            Intermediate

            Thanked: 15
            Re: Searching for files within subdirectories
            « Reply #4 on: February 03, 2010, 12:02:38 PM »

            "I have one of the files listed in the inlist in the directory and that gives an appropriate response in the Results.txt.  However it seems like nothing after the ValidCheck in the nested loop executes.  I figured it has something to do w/ me sending it to the end of file, but when I remove that it will execute down all of those other regions as well.  I even tried to put new regions within the loops to send it back to specific areas after execution however it bombs before it even does anything if you put regions within the for's."

            How did you create the inlist.txt   file?   Will  you post a few of the file names that are in the inlist file?

            I tried to run your code but I'm not sure what is in the inlist  file?

            Thanks
            Bill Richardson

            Grimbear13

              Topic Starter


              Rookie

              Re: Searching for files within subdirectories
              « Reply #5 on: February 03, 2010, 12:35:02 PM »
              I'm going to attempt to just give the entire package in a .zip.  I have been working out of the New Folder thats within there just to make sure that I can get it to do the primary task first (reading the list and verifying that the names in the list match the names of the files).

              [Saving space, attachment deleted by admin]

              BillRichardson



                Intermediate

                Thanked: 15
                Re: Searching for files within subdirectories
                « Reply #6 on: February 03, 2010, 03:23:28 PM »
                I'm going to attempt to just give the entire package in a .zip.  I have been working out of the New Folder thats within there just to make sure that I can get it to do the primary task first (reading the list and verifying that the names in the list match the names of the files).

                The zip file worked.  And the batch file ran.
                Of course, only one file  was found on my machine.

                ( I don't understand the need for the color change? But it worked. )

                Input:

                Review>type inlist

                Roof.txt
                Ceiling.txt
                Ground.txt
                Floor.txt
                Noob.txt
                Beginner.txt
                Decent Player.txt

                Output:

                Review>type Results
                ts.txt
                Roof.txt CHECK
                Ceiling.txt MISSING
                Ground.txt MISSING
                Floor.txt MISSING
                Noob.txt MISSING
                Beginner.txt MISSING
                Roof.txt CHECK
                Ceiling.txt MISSING
                Ground.txt MISSING
                Floor.txt MISSING
                Noob.txt MISSING
                Beginner.txt MISSING
                Roof.txt CHECK
                Ceiling.txt MISSING
                Ground.txt MISSING
                Floor.txt MISSING
                Noob.txt MISSING
                Beginner.txt MISSING
                Roof.txt CHECK
                Ceiling.txt MISSING
                Ground.txt MISSING
                Floor.txt MISSING
                Noob.txt MISSING
                Beginner.txt MISSING

                C:\Documents and Settings\Bill Richardson\Desktop\QA Review\QA Review>
                « Last Edit: February 03, 2010, 03:49:09 PM by BillRichardson »
                Bill Richardson

                BillRichardson



                  Intermediate

                  Thanked: 15
                  Re: Searching for files within subdirectories
                  « Reply #7 on: February 03, 2010, 03:43:58 PM »

                  Rem "color 0A"  was REMed out.
                  Rem "@echo off" was allowed to execute to cut down on volume of output

                  Code: [Select]
                  @echo off
                  rem  color 0A

                  for /F "tokens=*" %%I in (inlist) do (
                  Call :ResetBool
                  set filename=%%I

                          for /R %%K in (.) do (
                                  for %%J in (*) do (
                                  set file=%%J
                                  Call :ValidCheck
                                  echo HAMSTERS!
                  )
                                  )
                          Call :Print
                  )
                  GoTo :EOF

                  :ValidCheck
                  if %filename%==%file% (set bool=true)
                  GOTO :EOF

                  :Print
                  if %bool%==true (echo %filename% CHECK >> Results.txt
                  )else (echo %filename% MISSING >> Results.txt )
                  GOTO:EOF

                  :ResetBool
                  set bool=false
                  GoTo :EOF

                  Bill Richardson

                  BillRichardson



                    Intermediate

                    Thanked: 15
                    Re: Searching for files within subdirectories
                    « Reply #8 on: February 03, 2010, 06:15:40 PM »
                    Grim:

                    Your code works.  The only change was to change the main for loop to local variables with "setlocal enabledelayedexpansion"
                    ( I also placed all your files from the inlist in a subfolder called "trial" ). 

                    Code: [Select]
                    @echo off

                    setlocal enabledelayedexpansion
                    for /F "delims=" %%i in (inlist.txt) do (
                    rem Call :ResetBool
                    set filename=%%i
                    echo filename=!filename!


                            for /R %%K in (.) do (
                                    for %%J in (*) do (
                                    set file=%%J
                                    Call :ValidCheck
                                    echo HAMSTERS!
                    )
                                    )
                            Call :Print
                    )
                    GoTo :EOF

                    :ValidCheck
                    if %filename%==%file% (set bool=true)
                    GOTO :EOF

                    :Print
                    if %bool%==true (echo %filename% CHECK >> Results.txt
                    )else (echo %filename% MISSING >> Results.txt )
                    GOTO:EOF

                    :ResetBool
                    set bool=false
                    GoTo :EOF




                    C:\Review\type results.txt
                    Roof.txt CHECK
                    Ceiling.txt CHECK
                    Ground.txt CHECK
                    Floor.txt CHECK
                    Noob.txt CHECK
                    Beginner.txt CHECK
                    DecentPlayer.txt CHECK


                    « Last Edit: February 03, 2010, 06:33:27 PM by BillRichardson »
                    Bill Richardson

                    Grimbear13

                      Topic Starter


                      Rookie

                      Re: Searching for files within subdirectories
                      « Reply #9 on: February 05, 2010, 07:21:20 AM »
                      Okay, when I get some free time at work today hopefully I'll get to play around with it a bit haha.  Yeah I knew the code worked on files in the directory, my issue was getting into subdirectories.  I'll get back to you when I try your solution thanks for all the responses.

                      The color change was because that's my favorite color scheme, and the @echo off was commented out for debugging (as was the random "echo HAMSTERS!" in the one loop there was issues with execution of certain areas so I would put random outputs to make sure they were being executed...that one just got left it  :) )

                      Thanks Again hopefully I'll be able to get back with results.

                      Grimbear13

                        Topic Starter


                        Rookie

                        Re: Searching for files within subdirectories
                        « Reply #10 on: February 15, 2010, 12:53:03 PM »
                        Sorry for the super delayed response, but I just got a chance to try the change you suggested and my code still isn't finding any of the files in the subdirectories.  I tried both my code with your change and your code by itself (which gave a strange error about not being able to find the file at first).  But neither of them correctly reported that the files were there.

                        Also if you were wondering why there were extra files within the lower subdirectories it's because after I get this first step done I'm going to have it check all file names to what's in the list to ensure there are no extra files either.

                        Also it error's out on the Decent Players portion because of the space in the name, can you think of a way to remedy this?

                        Grimbear13

                          Topic Starter


                          Rookie

                          Re: Searching for files within subdirectories
                          « Reply #11 on: February 15, 2010, 12:59:51 PM »
                          Figure I'll post my latest code just to verify.  I broke out the nested loop because I'm trying to get it to terminate once it finds a match to save time.  Else for every object it will loop through the entire package and that will take considerable amounts of time with bigger packages.

                          Code: [Select]
                          @echo off
                          color 0A
                          ::The preceding line turns off screen printing and sets the text color to Bright Green.

                          ::Created by Scott Dean

                          ::Begins to search through the inlist file to get the names of the files.

                          setlocal enabledelayedexpansion
                          for /F "tokens=*" %%I in (inlist) do (
                          ::Calls the ResetBool function
                          Call :ResetBool
                          ::Sets filename equal to the value found from the inlist
                          set filename=%%I

                          ::Calls the two nested loops.  It is broken out this way because batch files do not
                          ::update variables until a process is terminated(not researched found by trial and error.
                          ::Therefore when if the loops are left to run the variables are never updated and incorrect
                          ::output will be given.
                          Call :LoopNest
                          ::Calls the Print function based on the bool variable's value will return MISSING or CHECK
                          Call :Print
                          )
                          GoTo :EOF

                          ::This function checks if the filename given from the inlist matches the current file.
                          :ValidCheck
                          if %filename%==%file% (set bool=true)
                          GOTO :EOF

                          ::This function prints whether the file is missing or not.
                          :Print
                          if %bool%==true (echo %filename% CHECK >> Results.txt
                          )else (echo %filename% MISSING >> Results.txt )
                          GOTO:EOF

                          ::Resets the value of the bool variable to be defaulted to false.
                          :ResetBool
                          set bool=false
                          GoTo :EOF

                          ::Pair of nested for's called from the first for loop.  These go into the subdirectories
                          ::and call the functions ValidCheck and BoolCheck. (May not go into subdirectories as of 02-08-2010)
                          :LoopNest
                          for /R %%K in (.) do (
                          for %%J in (*) do (
                          set file=%%J
                          Call :ValidCheck
                          Call :BoolCheck
                          if %bool%==true (GOTO :EOF)
                          )
                          if %bool%==true (GOTO :EOF)
                          )
                          GOTO :EOF

                          ::An attempt to break the loop cycle if the correct value is found, doesn't seem to work.
                          :BoolCheck
                          if %bool%==true (GOTO :EOF)

                          BC_Programmer


                            Mastermind
                          • Typing is no substitute for thinking.
                          • Thanked: 1140
                            • Yes
                            • Yes
                            • BC-Programming.com
                          • Certifications: List
                          • Computer: Specs
                          • Experience: Beginner
                          • OS: Windows 11
                          Re: Searching for files within subdirectories
                          « Reply #12 on: February 15, 2010, 10:14:53 PM »
                          when you have loops it's not really a good idea to use two colons to indicate a comment.
                          I was trying to dereference Null Pointers before it was cool.

                          Grimbear13

                            Topic Starter


                            Rookie

                            Re: Searching for files within subdirectories
                            « Reply #13 on: February 16, 2010, 09:09:44 AM »
                            By loops are you referring to the regions or within the loops?  I don't know standards for batches and I just find it easier to type :: rather than rem.  Also coming from a C (primarily C#) background I'm more comofortable with the :: beacuse its similar to the // comment.  I think the constant spam of rem in the code makes it harder to read.

                            BC_Programmer


                              Mastermind
                            • Typing is no substitute for thinking.
                            • Thanked: 1140
                              • Yes
                              • Yes
                              • BC-Programming.com
                            • Certifications: List
                            • Computer: Specs
                            • Experience: Beginner
                            • OS: Windows 11
                            Re: Searching for files within subdirectories
                            « Reply #14 on: February 16, 2010, 09:41:57 AM »
                            :: within the body of the loop can cause problems, since : is really a label delimiter.

                            the only "legitimate" comment is REM, and really that's just an internal command that does nothing.
                            I was trying to dereference Null Pointers before it was cool.

                            Grimbear13

                              Topic Starter


                              Rookie

                              Re: Searching for files within subdirectories
                              « Reply #15 on: February 16, 2010, 09:49:49 AM »
                              the only "legitimate" comment is REM, and really that's just an internal command that does nothing.

                              Well isn't that what any comment is a line that does nothing?  They're there to put what is going on in the code into "human" language.

                              But anyways back to my issues w/ the code.  I was having these issues long before I put comments in.  I wrote the entire thing and then went back and commented it because I'm writing these for my job and if I'm either not with the company or not in the same department I want people to be able to use my scripts and understand what they do.

                              Sidewinder



                                Guru

                                Thanked: 139
                              • Experience: Familiar
                              • OS: Windows 10
                              Re: Searching for files within subdirectories
                              « Reply #16 on: February 16, 2010, 03:03:48 PM »
                              As a follower of KISS theory, I humbly submit this little snippet. Only thing I couldn't accomplish was to break going through the directory list once a match was found. Keep in mind, batch code is not a programming language, it's a command language.

                              Code: [Select]
                              @echo off
                              if exist Review.txt del Review.txt
                              setlocal enabledelayedexpansion
                              for /f "tokens=* delims=" %%i in (inList.txt) do (
                                set lit=MISSING
                                for /f "tokens=* delims=" %%x in ('dir drive:\path /s /b') do (
                                  if /i %%i==%%~nx%%~xx set lit=CHECK
                                )
                                echo %%i - !lit! >> Review.txt
                                set lit=MISSING
                              )
                              endlocal

                              Replace drive:\path with the top level directory name you want to start the search.

                              Good luck.  8)

                              Using :: for comments is fine, just don't use them within for loops.
                              « Last Edit: February 16, 2010, 03:17:10 PM by Sidewinder »
                              The true sign of intelligence is not knowledge but imagination.

                              -- Albert Einstein

                              Grimbear13

                                Topic Starter


                                Rookie

                                Re: Searching for files within subdirectories
                                « Reply #17 on: February 17, 2010, 01:48:32 PM »
                                Busy all day didn't get to play with this, thanks for the response though

                                Code: [Select]
                                for /f "tokens=* delims=" %%x in ('dir drive:\path /s /b') do (
                                To get this to run from the current directory would it be:

                                Code: [Select]
                                for /f "tokens=* delims=" %%x in ('dir . /s /b') do (?

                                I need it to run from where I put the batch because each time the path is going to be different and it's pointless to have to change the batch every time it is to be run.

                                Two side notes:
                                1) What is KISS theory
                                2) What kind of issues do the :: cause within a for?

                                Salmon Trout

                                • Guest
                                Re: Searching for files within subdirectories
                                « Reply #18 on: February 17, 2010, 02:12:32 PM »
                                Two side notes:
                                1) What is KISS theory
                                2) What kind of issues do the :: cause within a for?

                                KISS stands for Keep It Simple, Stupid, and is a humorous way of expressing the view that unnecessary complication is undesirable and attracts problems.

                                The use of the unsupported, undocumented, deprecated :: double colon as a comment line starter causes problems in a loop or other parenthetical structure because cmd.exe regards a structure of this type...

                                Code: [Select]
                                blah blah blah (
                                    blah blah
                                    blah blah
                                    blah blah
                                    )
                                ...as being all one line. The double colon is a broken label. A label can only occur at the beginning of a line, so its use breaks the parenthetical structure.



                                Sidewinder



                                  Guru

                                  Thanked: 139
                                • Experience: Familiar
                                • OS: Windows 10
                                Re: Searching for files within subdirectories
                                « Reply #19 on: February 17, 2010, 02:14:27 PM »
                                Quote
                                I need it to run from where I put the batch because each time the path is going to be different and it's pointless to have to change the batch every time it is to be run.

                                You could always prompt for the directory to start with:

                                Code: [Select]
                                @echo off
                                if exist Review.txt del Review.txt
                                setlocal enabledelayedexpansion
                                set /p root=Enter Start Directory:
                                for /f "tokens=* delims=" %%i in (inList.txt) do (
                                  set lit=MISSING
                                  for /f "tokens=* delims=" %%x in ('dir %root% /s /b') do (
                                    if /i %%i==%%~nx%%~xx set lit=CHECK
                                  )
                                  echo %%i - !lit! >> Review.txt
                                  set lit=MISSING
                                )
                                endlocal

                                Quote
                                What is KISS theory

                                Stands for "Keep It Simple Stupid". I keep repeating it to myself everytime I start to write a program or script. ;D

                                Quote
                                What kind of issues do the :: cause within a for?

                                It will throw an error. You can have a goto but the :label must be outside the outermost for loop.

                                Good luck.  8)


                                The true sign of intelligence is not knowledge but imagination.

                                -- Albert Einstein

                                Grimbear13

                                  Topic Starter


                                  Rookie

                                  Re: Searching for files within subdirectories
                                  « Reply #20 on: February 17, 2010, 02:36:19 PM »
                                  Thanks both of you, the script started off simple enough but then when I started not getting the results I expected I started finding out how the code executes and was breaking it out into the multi-tier program you saw there.

                                  Would the . allow it to run in the present directory?  I could prompt it, but I'm trying to set this up to have a little user input as possible.  For myself it wouldn't be too much of an issue more than an annoyance.  However once other people start using it I can forsee an issue coming up.

                                  And thanks for the indepth explainations of the ::.  Like I said I just don't like the look of rem preceeding every line of comments I think it looks cluttered and I'm beggining to believe I have some kind of Dyslexia or an advanced form of ADD where when reading things like that if it looks to cluttered I'll instantly dismiss it and even if I try to read it I won't comprehend it.

                                  Salmon Trout

                                  • Guest
                                  Re: Searching for files within subdirectories
                                  « Reply #21 on: February 17, 2010, 02:38:45 PM »
                                  I need it to run from where I put the batch because each time the path is going to be different and it's pointless to have to change the batch every time it is to be run.

                                  Put it in your Send To folder, (or store it anywhere you like and put a shortcut to it in the Send To folder) and then you can right click a folder and "send it" (i.e. the full drive letter and path in quotes) to the batch. Just add this line to the start of the batch script right after @echo off...

                                  Or store it or a shortcut to it on your desktop and drag and drop a folder onto it for the same effect

                                  Code: [Select]
                                  cd /d %1
                                  « Last Edit: February 17, 2010, 03:33:42 PM by Salmon Trout »

                                  Grimbear13

                                    Topic Starter


                                    Rookie

                                    Re: Searching for files within subdirectories
                                    « Reply #22 on: February 18, 2010, 09:53:23 AM »
                                    Thanks Salmon,

                                    I think my wording was a little peculiar.  I do plan on always copying the batch into where it needs to be run and more than likely the last step in the process will be to delete itself to minimize clean up afterwards so it doesn't get mixed in with the other files.

                                    Salmon Trout

                                    • Guest
                                    Re: Searching for files within subdirectories
                                    « Reply #23 on: February 18, 2010, 11:35:57 AM »
                                    the last step in the process will be to delete itself

                                    To make a batch file delete itself

                                    Code: [Select]
                                    del "%~dpnx0"

                                    Grimbear13

                                      Topic Starter


                                      Rookie

                                      Re: Searching for files within subdirectories
                                      « Reply #24 on: February 18, 2010, 12:24:10 PM »
                                      I have made them delete themselves before.  What I need to make it do is not require any inputs or altering.  To just be able to be dropped in a directory with the inlist that will be created and run, checking all files in the directories and sub directories.

                                      Grimbear13

                                        Topic Starter


                                        Rookie

                                        Re: Searching for files within subdirectories
                                        « Reply #25 on: February 18, 2010, 12:31:10 PM »
                                        My theory of the 'dir .' works for what I need it.  Thank you all.  However I just noticed when you output the lit variable you used !lit!.  Can you explian why you would use the ! instead of the %'s?

                                        Grimbear13

                                          Topic Starter


                                          Rookie

                                          Re: Searching for files within subdirectories
                                          « Reply #26 on: February 18, 2010, 12:58:04 PM »
                                          New issue thanks to the code provided by Sidewinder I was able to modify it slightly to execute the way I wanted.  Then I wrote the second half of it to do the inverse and check all files within the directory next to the list in order to see if there are any extra files.  When I had it running as it's own batch it performed exactly as I wanted it to, however now when it's under the first section so they run in sequence it seem to print lit2 for the first 3 lines of the output.

                                          Also it is printing the names of the folders, is there a way to get it to bypass folder names?  The folder names aren't going to be listed in the document ever, and will be checked in a different process.

                                          Code: [Select]
                                          @echo off
                                          @color 0A

                                          if exist !MissingFiles.txt del !MissingFiles.txt

                                          setlocal enabledelayedexpansion
                                          for /f "tokens=* delims=" %%i in (inList) do (
                                            set lit=MISSING

                                            for /f "tokens=* delims=" %%x in ('dir . /s /b') do (
                                              if %%i==%%~nx%%~xx set lit=CHECK
                                            )

                                            echo %%i - !lit! >> !MissingFiles.txt
                                            set lit=MISSING
                                          )

                                          if exist !ExtraFiles.txt del !ExtraFiles.txt

                                          setlocal enabledelayedexpansion
                                          for /f "tokens=* delims=" %%j in ('dir . /s /b') do (
                                            set lit2=EXTRA

                                            for /f "tokens=* delims=" %%y in (inList) do (
                                              if %%y==%%~nj%%~xj set lit2=CHECK
                                            )
                                            echo %%~nj%%~xj - !lit2! >> !ExtraFiles.txt
                                            set lit2=EXTRA
                                          )
                                          endlocal

                                          Also I need this to be case sensitive, thats why I removed the /i in the if.

                                          Thank You everyone for your help, not only is it forwarding this project.  But it is also expanding my knowledge of how to these work and how to write them. :)

                                          Grimbear13

                                            Topic Starter


                                            Rookie

                                            Re: Searching for files within subdirectories
                                            « Reply #27 on: March 01, 2010, 09:51:11 AM »
                                            I'm going to post this in a new topic as well, but I was hoping that some of you whom helped me previously would be able to because it applies to this project of mine.  This is the current version of the batch I was writing.  However when it's parsing through either the file names or the inlist if the file name has a space in it it is breaking it down into multiple objects, using hte " " as a delim.  In a for loop is there a way to make it delim at the end of a line as opposed to any white space?

                                            Code: [Select]
                                            @echo off
                                            @color 0A

                                            if exist !MissingFiles.txt del !MissingFiles.txt

                                            setlocal enabledelayedexpansion
                                            for /f "tokens=* delims=" %%i in (inList) do (
                                              set lit=MISSING

                                              for /f "tokens=* delims=" %%x in ('dir . /s /b') do (
                                                if %%i==%%~nx%%~xx set lit=CHECK
                                              )

                                              echo %%i - !lit! >> !MissingFiles.txt
                                              set lit=MISSING
                                            )

                                            if exist !ExtraFiles.txt del !ExtraFiles.txt

                                            setlocal enabledelayedexpansion
                                            for /f "tokens=* delims=" %%j in ('dir . /s /b') do (
                                              set lit2=EXTRA

                                              for /f "tokens=* delims=" %%y in (inList) do (
                                                if %%y==%%~nj%%~xj set lit2=CHECK
                                              )
                                              echo %%~nj%%~xj - !lit2! >> !temp.txt
                                              set lit2=EXTRA
                                            )

                                            find "." !temp.txt | find /i /v ".doc" | find /i /v ".xls" | find /i /v ".rtf" | find /i /v "MissingFiles.txt" >> !ExtraFiles.txt

                                            del !temp.txt

                                            endlocal

                                            ALAN_BR



                                              Hopeful

                                              Thanked: 5
                                              • Computer: Specs
                                              • Experience: Experienced
                                              • OS: Windows 7
                                              Re: Searching for files within subdirectories
                                              « Reply #28 on: March 01, 2010, 01:23:40 PM »
                                              Can you explian why you would use the ! instead of the %'s?

                                              When subject to "setlocal enabledelayedexpansion" then ! is similar to %,
                                              with the exception that within brackets then % uses the value preceding the opening bracket.
                                              Try :-
                                              Code: [Select]
                                              @echo off
                                              setlocal enabledelayedexpansion
                                              set var=3
                                              (
                                              set var=4
                                              echo %var% !var!
                                              )
                                              pause

                                              Alan

                                              Grimbear13

                                                Topic Starter


                                                Rookie

                                                Re: Searching for files within subdirectories
                                                « Reply #29 on: March 02, 2010, 08:07:18 AM »
                                                I'm sorry I got caught up in work yesterday and a collegue pointed out a possible issue.  It wasn't the spaces in the code that were causing the issue.  Whomever was naming the files that I was running this against was using an irregular dash.  Even when copying the name directly it wasn't finding it.  Thank You to everyone who replied.

                                                I thought that this script worked with spaces and I even checked it against an older job I did and it worked.