|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
Walking a directoryI need to remotely walk the directories in a group of shares on a server
to dump a couple of files in each directory. Any help would be appreciated. Regards Lamar Morris Texas Instruments - IT Operations - Windows Server Team * <mailto:LamarMorris@...> email: LamarMorris@... - *office: 214-567-7169 * <mailto:searun@...> team email: wst@... - *mobile: 214-882-4187 *web: <http://wst.itg.ti.com/> http://wst.itg.ti.com/ <http://wst.itg.ti.com/> [Non-text portions of this message have been removed] |
|
|
Re: Walking a directoryOn Tue, 10 Jun 2008 15:44:10 -0500, "Morris, Lamar" <LamarMorris@...>
wrote: >I need to remotely walk the directories in a group of shares on a server >to dump a couple of files in each directory. Any help would be >appreciated. Will this help? It'll provide a list of *.bat files for example. @echo off for %%z in ( "share1" "share2" "share3" ) do ( for /f "delims=" %%a in ( 'dir "\\server\%%~z\*.bat" /o:n /b /s' ) do echo "%%a">>filelist.txt ) |
|
|
RE: Walking a directoryThanks Mic, I'll see if I can modify it to do what I need.
Lamar ________________________________ From: batchworld@... [mailto:batchworld@...] On Behalf Of foxidrive Sent: Tuesday, June 10, 2008 7:33 PM To: batchworld@... Subject: Re: [BATCH WORLD] Walking a directory On Tue, 10 Jun 2008 15:44:10 -0500, "Morris, Lamar" <LamarMorris@... <mailto:LamarMorris%40ti.com> > wrote: >I need to remotely walk the directories in a group of shares on a server >to dump a couple of files in each directory. Any help would be >appreciated. Will this help? It'll provide a list of *.bat files for example. @echo off for %%z in ( "share1" "share2" "share3" ) do ( for /f "delims=" %%a in ( 'dir "\\server\%%~z\*.bat" /o:n /b /s' ) do echo "%%a">>filelist.txt ) [Non-text portions of this message have been removed] |
|
|
RE: Walking a directoryYou can also use pushd to do this
pushd \\server\share for /R %%p in (*.bat) do echo %%p popd The pushd instruction will create a new letter drive for the share and then you can walk the path just like any other folder. If you are going to do something risky in the loop (like deleting files) use the narrowest wildcards you can (as far away from *.* as you can). You can also verify that the pushd operation succeeded by checking that the folder name changed and that errorlevel is 0 after the pushd. set CURRENTFOLDER=%cd% pushd \\server\share if errorlevel 1 echo pushd failed & exit /B 1 if "%CURRENTFOLDER%"==%cd% echo pushd did not change the current folder location. Aborting&exit /B 1 ... ... You can also execute the instructions step by step using Running Steps. The debugger for batch files (http://www.steppingsoftware.com). It will even unroll the loops if you step into them. Hope this helps. GISkier
|
| Free Forum Powered by Nabble | Forum Help |