The following command creates an infinite loop which is not what I want since I am iterating through files and it needs to end sometime...
Here is what I have:
cd C:\
FOR /R %i IN (*.pst) do @echo %i
See what happens is that when it reaches AppData and finds a .pst (in AppData\Local\Microsoft\Outlook) there is a shortcut folder inside AppData\Local called "Application Data" which loops back to AppData\Local but keeps adding it's name to the address like so:
%AppData%\Local\Application Data\Application Data\Application Data\Microsoft\Outlook\%filename%.pst
What could I add to my code to keep it from looping or much better to completely ignore shortcuts so that the loop ends when it finds all the files that I need?
-----------Edit-------------
This seems to do something similar:
dir /s /b *.pst
You can filter out reparse points with DIR /A-L
.
However, using DIR /A-L /S
won't work also, because reparse point contents are not reparse points, so, try this:
Instead of FOR
use:
FindFiles.bat *.pst c:\
Create a FindFiles.bat
file with:
@ECHO OFF
:GetDirFiles %1=Wildcard %2=Path
FOR %%f IN ("%~f2\%~1") DO ECHO %%~ff
FOR /F "DELIMS=" %%d IN ('DIR /B /AD-L "%~f2"') DO CALL :GetDirFiles %1 "%~2\%%d"
This will recursivelly get all directories which are not reparse points and echo items matching pattern for each directory.
Ok, I recommend you use forfiles
which should be on your computer if your using windows 7. Type forfiles /?
for more info. Try this:
forfiles /p "C:\" /s /m "*.pst" /c "cmd /c (Echo @path)"
That should work perfectly. Im looking in ways of doing this with a for /r
loop. It probably involves a dir
check in a for /r /d
. Tell me if this works fine for you.
Mona