![]() ![]() I will explain how you can view, add, and delete network shares from the cmd line. In this article, we are going to take a closer look at the Net Use command. ![]() Mapping Network Drive with different credentials.To replicate, try using it (slightly modified to look only on one disk and to provide some feedback) on a disk (say A:\ ) where "test.cmd" is in:īUT with the actual batch residing in a directory on C:\ containing a number of OFFSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONSET /A Counter=0DIR /B /S A:PAUSESET FindFile=mytest.cmdSET FoundFile=NopeCALL :IsItThere "A:" %FindFile% FoundFileIF "!FoundFile!" NEQ "Nope" GOTO :FOUNDECHO ERROR: "%FindFile%" not found.PAUSEEXIT /b:FOUNDECHO File "%FindFile%" found in "%FoundFile%".ENDLOCALPAUSEEXIT /b:IsItThereSET /A Counter+=1SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONSET Result=NopeIF EXIST "%~dp1%2" ((SET "Result=%~dp1")&GOTO :DONE)FOR /F "tokens=*" %%G IN ('dir /B /AD "%~dp1"') DO (IF !Counter!=6 GOTO :DONEECHO !Counter! "%~dp1" CALL :IsItThere "%%G" %2 ResultCALL :IsItThere "%%G" %2 ResultIF "!Result!" NEQ "Nope" GOTO :DONE):DONEENDLOCAL&(SET %3=%Result%)&EXIT /B 0This is what I get:ġ "A:\" CALL :IsItThere "Afolder" mytest.cmd ResultĢ "C:\batches\" CALL :IsItThere "Atest" mytest.cmd Resultģ "C:\batches\" CALL :IsItThere "Atest" mytest.cmd ResultĤ "C:\batches\" CALL :IsItThere "Atest" mytest.cmd Resultĥ "C:\batches\" CALL :IsItThere "Atest" mytest.cmd Resultĥ "C:\batches\" CALL :IsItThere "BCDedit_batch" mytest.cmd ResultĤ "C:\batches\" CALL :IsItThere "BCDedit_batch" mytest.cmd Resultĥ "C:\batches\" CALL :IsItThere "CmdasSystem" mytest.cmd Resultģ "C:\batches\" CALL :IsItThere "BCDedit_batch" mytest.cmd ResultĤ "C:\batches\" CALL :IsItThere "CmdasSystem" mytest.cmd Resultĥ "C:\batches\" CALL :IsItThere "CRCMD5" mytest.cmd Result ****** ELABORAZIONE BATCH TERMINATA *********Įrror on my XP, I can confirm that your approach is *somehow* not the best one. ****** RICORSIONE BATCH supera i limiti dello STACK******Ĭonteggio ricorsione=753, utilizzo stack=90 percento Just for the record, the bhplt example seemingly only looks for the file in root (which may or may not be what the OP wants)., and nowadays it makes little sense (unless there is a reason for it) to look for files in the A: or B: drive The suggested tool is MIA (but can be obtained through the Wayback Machine): If the volume is NTFS formatted, using a search tool parsing just the $MFT will result as waaaay faster. Yep, the point on the other thread being (besides the nice sample by Yzöwl) that using DIR /S on a largish (possibly filled up to the brim) volume will be slow. Can only suggest to use delayed expansion with the variables to help avoid character issues. I can not fix something that is not broken. It even looks rather similar to the code in the link that jaclaz posted that was done by Yzöwl. I do not see how it can fail unless %FoundFile% contained some special characters which possibly could foul it up. The script in the 1st post has been tested here as working in Windows 7 X64. Also, for a system with many terabytes of files this is likely to take quite awhile. ![]() The code does not deal with possibilities such as MOUNTVOL returning a drive letter for a CD or DVD drive that does not have a disc in it and other annoyances. You will need to ensure that the cases of all valid possible path and file names are accounted for such as spaces and other troublesome characters such as ' and ) etc. ![]() Using your code as a beginning point, here is a START at a OFF & SETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONSET FindFile=test.cmdSET FoundFile=NopeFOR /F %%a IN ('MOUNTVOL^|FINDSTR :\\') do ( CALL :IsItThere "%%a" %FindFile% FoundFile IF "!FoundFile!" NEQ "Nope" GOTO :FOUND ))ECHO ERROR: "%FindFile%" not found.PAUSEEXIT /b:FOUNDECHO File "%FindFile%" found in "%FoundFile%".ENDLOCALPAUSEEXIT /b :IsItThereSETLOCAL ENABLEEXTENSIONS ENABLEDELAYEDEXPANSIONSET Result=NopeIF EXIST "%~dp1%2" ((SET "Result=%~dp1")&GOTO :DONE)FOR /F "tokens=*" %%G IN ('dir /B /AD "%~dp1"') DO ( CALL :IsItThere "%%G" %2 Result IF "!Result!" NEQ "Nope" GOTO :DONE):DONEENDLOCAL&(SET %3=%Result%)&EXIT /B 0 ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |