|
Answer» grant, here it is. code becomes longer with the additional feature, i've try my BEST to make it as compact as possible. the below code will run version 1, if you want to run version 2, comment the line call:version 1 and uncomment call:version 2.
Code: [Select]::NetBackup.bat @echo off & setlocal enabledelayedexpansion & cls
set/p copy_dir=Input Directory to COPY to (eg. c:\test\) : set copy_dir || goto:eof if not exist %copy_dir% md %copy_dir%
set vPath=&set vUser= echo.Input Full Path (eg: \\remote-pc\sharefolder or c:\data or .) & set/p vPath=- ::set vPath || call:interface set vPath || goto:eof echo.&set/p vUser=Input Full User Name to Search (eg: %computername%\%username%) : set vUser || goto:eof
echo.&echo Mapping %vPath% to next available drive letter PUSHD %vPath% && (echo Success!!) || goto:eof
call:version1 &REM version1 code is short but took longer time to execute ::call:version2 &REM version2 code is longer but took less time to execute
popd goto:eof
:version1 echo.&echo.Running Version 1... for /r %%a in (*) do ( dir/q/a-d "%%a"|find/i "%vUser% ">nul 2>&1 && ( echo %%~fa copy "%%a" "%copy_dir%" 1>&2 ) ) goto:eof
:version2 echo.&echo.Running Version 2... time/t|find " ">nul && set/a A=5,B=0||set/a A=4,B=0 for /f %%a in ('echo."%vUser: ="^&echo."%"') do if not %%~a.==. set/a B+=1
set/a token=A+B-1 set token=%A%-%token%* set token
for /l %%a in (1 1 %B%) do call set u=%%u%%%%%%%%a set/a B+=1 for /r /d %%a in (.) do ( pushd %%~fa for /f "skip=5 tokens=%token%" %%1 in ('dir/q/a-d "%%~fa" 2^>nul') do ( if /i "%u%"=="%vUser% " ( echo %%~f%B% copy "%%~f%B%" "%copy_dir%" 1>&2 ) ) popd ) goto:eof
i've also written an interface to view network computer and its share folder, you can plug the code into the bottom NetBackup.bat if you wish to use it. Code: [Select]:interface ::The following is the interface to look for network pc and network shared folder echo.&set/p c=Do you want to run interface (y/n) ? if /i "%c%" neq "y" goto:eof
echo.&set/p vCompName=Input Computer Name (or blank to search) : 2>nul set vCompName || ( for /f "tokens=1,2* delims=[] " %%a in ('net view^|more +3^|find/n "\\"') do ( set v%%a=%%b& echo %%a. %%b) set c=&set/p c=Enter Choice : call set vCompName=%%v!c!%% set vCompName || goto:eof )
echo.&set/p vFolder=Input Folder Name (or blank to search) : 2>nul set vFolder || ( for /f "tokens=1-3* delims=[] " %%a in ('net view %vCompName%^|more +7^|find/n " Disk "') do ( set f%%a=%%b& echo %%a. %%b %%c %%d) set c=&set/p c=Enter Choice : call set vFolder=%%f!c!%% set vFolder || goto:eof )
set vPath=%vCompName%\%vFolder%
Quote from: Grant123 on March 20, 2009, 08:44:12 AM so at this point, I give up on DECIPHERING your code but I'll run it and trust that it works!
there is only one way to make to code more readable, modify it to become longer by using the usual syntax, eg lots of if else if else, set, for, etc.
i just notice that for network share, the owner file name is not computername\username, but something like this: Code: [Select]05/30/2008 03:49 AM <DIR> \Everyone FolderA 04/23/1999 07:22 AM 93,890 \Everyone COMMAND.COM 05/11/1998 05:01 AM 33,191 ... HIMEM.SYS 03/07/2009 01:34 AM 85,504 BUILTIN\Administrators sample.txt Quote from: Reno on March 21, 2009, 03:55:36 AMgrant, here it is. code becomes longer with the additional feature, i've try my best to make it as compact as possible. the below code will run version 1, if you want to run version 2, comment the line call:version 1 and uncomment call:version 2.
Code: [Select]::NetBackup.bat @echo off & setlocal enabledelayedexpansion & cls
set/p copy_dir=Input Directory to copy to (eg. c:\test\) : set copy_dir || goto:eof if not exist %copy_dir% md %copy_dir%
set vPath=&set vUser= echo.Input Full Path (eg: \\remote-pc\sharefolder or c:\data or .) & set/p vPath=- ::set vPath || call:interface set vPath || goto:eof echo.&set/p vUser=Input Full User Name to Search (eg: %computername%\%username%) : set vUser || goto:eof
echo.&echo Mapping %vPath% to next available drive letter pushd %vPath% && (echo Success!!) || goto:eof
call:version1 &REM version1 code is short but took longer time to execute ::call:version2 &REM version2 code is longer but took less time to execute
popd goto:eof
:version1 echo.&echo.Running Version 1... for /r %%a in (*) do ( dir/q/a-d "%%a"|find/i "%vUser% ">nul 2>&1 && ( echo %%~fa copy "%%a" "%copy_dir%" 1>&2 ) ) goto:eof
:version2 echo.&echo.Running Version 2... time/t|find " ">nul && set/a A=5,B=0||set/a A=4,B=0 for /f %%a in ('echo."%vUser: ="^&echo."%"') do if not %%~a.==. set/a B+=1
set/a token=A+B-1 set token=%A%-%token%* set token
for /l %%a in (1 1 %B%) do call set u=%%u%%%%%%%%a set/a B+=1 for /r /d %%a in (.) do ( pushd %%~fa for /f "skip=5 tokens=%token%" %%1 in ('dir/q/a-d "%%~fa" 2^>nul') do ( if /i "%u%"=="%vUser% " ( echo %%~f%B% copy "%%~f%B%" "%copy_dir%" 1>&2 ) ) popd ) goto:eof
i've also written an interface to view network computer and its share folder, you can plug the code into the bottom NetBackup.bat if you wish to use it. Code: [Select]:interface ::The following is the interface to look for network pc and network shared folder echo.&set/p c=Do you want to run interface (y/n) ? if /i "%c%" neq "y" goto:eof
echo.&set/p vCompName=Input Computer Name (or blank to search) : 2>nul set vCompName || ( for /f "tokens=1,2* delims=[] " %%a in ('net view^|more +3^|find/n "\\"') do ( set v%%a=%%b& echo %%a. %%b) set c=&set/p c=Enter Choice : call set vCompName=%%v!c!%% set vCompName || goto:eof )
echo.&set/p vFolder=Input Folder Name (or blank to search) : 2>nul set vFolder || ( for /f "tokens=1-3* delims=[] " %%a in ('net view %vCompName%^|more +7^|find/n " Disk "') do ( set f%%a=%%b& echo %%a. %%b %%c %%d) set c=&set/p c=Enter Choice : call set vFolder=%%f!c!%% set vFolder || goto:eof )
set vPath=%vCompName%\%vFolder%
there is only one way to make to code more readable, modify it to become longer by using the usual syntax, eg lots of if else if else, set, for, etc.
i just notice that for network share, the owner file name is not computername\username, but something like this: Code: [Select]05/30/2008 03:49 AM <DIR> \Everyone FolderA 04/23/1999 07:22 AM 93,890 \Everyone COMMAND.COM 05/11/1998 05:01 AM 33,191 ... HIMEM.SYS 03/07/2009 01:34 AM 85,504 BUILTIN\Administrators sample.txt
Reno - I didn't get a chance to REPLY to this last message. The project's been pushed back farther and farther and I expect to be using this tool in June some time. You've saved me tons of time and I really appreciate it! Thanks!
|