While searching for .pst files FOR keeps looping when it reaches a hidden shortcut folder

≡放荡痞女 提交于 2019-12-11 02:12:24

问题


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

回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/18747723/while-searching-for-pst-files-for-keeps-looping-when-it-reaches-a-hidden-shortc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!