RE: file searching and copying
Hey, Scott 1. I left it there so the IP could see it run and decide how to use the data. 2. Possibly, but it was quick and dirty. Doesn't hurt with the p 3. Yes it does, and I forgot to remove that. Interestingly enough, it only causes a problem undoubtedly after the drive letter. Elsewhere in the path, it works just fine. 4. Good catch 5. Yes, but you have to do it all on one line. I separate the commands with a single within the parentheses The goal was to give him enough data to decide hour to implement it for his environment. -ASB: http://about.me/Andrew.S.Baker Sent from my Motorola Droid On Jul 20, 2011 7:50 PM, Crawford, Scott crawfo...@evangel.edu wrote: ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: file searching and copying
I thought the /s /e was redundant when I first saw it too. The xcopy docs differ on the usage however: From Help and Support Center docs: /s Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory. /e Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options. command line (xcopy /?) /S Copies directories and subdirectories except empty ones. /E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. On Wed, Jul 20, 2011 at 7:49 PM, Crawford, Scott crawfo...@evangel.eduwrote: Nice to see pushd and popd making an appearance J ** ** Few nits and questions, just to make sure I’m not missing something: ** ** **1. **The echo in front of xcopy shouldn’t be there. I’m sure it’s just there for troubleshooting and left as an oversight. The /s /e is redundant, right? **2. **I’m not very practiced with the enhanced ~ substitution, but couldn’t the SET @DIR=%%~fpv line omit the p? **3. **I think the ECHO DEST: %@DEST%\%%~pv line has an extra \*** * **4. **I think the xcopy’s destination parameter (%@DEST%%%~pv)needs to be %@DEST%%%~pnv. Without it, the files get copied into the corresponding parent on the destination. **5. **Is there any way to get the parentheses code blocks work from the command line or do they need to be inside of a .bat? I’ve tried stringing the commands together with , but met with limited success. ** ** Possible drawback to this method: The destination path will contain the full path of the source. For instance, if the source root is C:\a\b\c and it contains a folder called Search_Term, and we wan’t the destination to be D:\, when we run the script, the destination will contain D:\a\b\c\Search_Term, which may not be the goal. ** ** In the end, I don’t think this is getting any better results the my original line. The 2NUL is just hiding the failures. ** ** Thanks for the script though, it was fun to digest J ** ** *From:* Andrew S. Baker [mailto:asbz...@gmail.com] *Sent:* Wednesday, July 20, 2011 3:06 PM *To:* NT System Admin Issues *Subject:* Re: file searching and copying ** ** How long are the paths? There are other ways to handle this, btw... Try the following snippet. It should handle long folders even if Windows complains about them @echo off SETLOCAL ENABLEDELAYEDEXPANSION SET @SOURCE=%SystemDrive% SET @DEST=D:\SomePlace SET @FIND=PrivacIE :Main for /f tokens=* %%v in ('dir /ad /b /s %@SOURCE%\*.* 2^NUL ^| FIND /I %@FIND%') do ( SET @DIR=%%~fpv ECHO. ECHO SOURCE: !@DIR! ECHO DEST: %@DEST%\%%~pv PUSHD !@DIR! echo XCOPY *.* %@DEST%%%~pv /S /E /R /Y ECHO. POPD ) ** ** ** ** :ExitBatch ENDLOCAL *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market…* On Wed, Jul 20, 2011 at 2:24 PM, Jeff Bunting bunting.j...@gmail.com wrote: Thanks all. Scott's suggestion is close and at least got me pointed in the right direction. Some of the paths are too long for DIR which throws a wrench in the works, so I'm going to have to rely on windows search for now. Powershell, unfortunately, currently isn't an option. Jeff On Wed, Jul 20, 2011 at 12:23 PM, Andrew S. Baker asbz...@gmail.com wrote: Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. ** ** *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market…* On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.edu wrote: For /f “tokens=*” %i in (‘dir *WORDS_TO_SEARCH* /s/a/b/ad’) do robocopy /mir “%i” DESTINATION_PATH This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. *From:* Jeff Bunting [mailto:bunting.j...@gmail.com] *Sent:* Wednesday, July 20, 2011 11:01 AM *To:* NT System Admin Issues *Subject:* file searching and copying I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ** ** ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here
Re: file searching and copying
/E implies /S Out of habit I put them both, all the time. * * *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market… * On Thu, Jul 21, 2011 at 10:37 AM, Jeff Bunting bunting.j...@gmail.comwrote: I thought the /s /e was redundant when I first saw it too. The xcopy docs differ on the usage however: From Help and Support Center docs: /s Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory. /e Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options. command line (xcopy /?) /S Copies directories and subdirectories except empty ones. /E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. On Wed, Jul 20, 2011 at 7:49 PM, Crawford, Scott crawfo...@evangel.eduwrote: Nice to see pushd and popd making an appearance J ** ** Few nits and questions, just to make sure I’m not missing something: ** ** **1. **The echo in front of xcopy shouldn’t be there. I’m sure it’s just there for troubleshooting and left as an oversight. The /s /e is redundant, right? **2. **I’m not very practiced with the enhanced ~ substitution, but couldn’t the SET @DIR=%%~fpv line omit the p? **3. **I think the ECHO DEST: %@DEST%\%%~pv line has an extra \** ** **4. **I think the xcopy’s destination parameter (%@DEST%%%~pv)needs to be %@DEST%%%~pnv. Without it, the files get copied into the corresponding parent on the destination. **5. **Is there any way to get the parentheses code blocks work from the command line or do they need to be inside of a .bat? I’ve tried stringing the commands together with , but met with limited success.*** * ** ** Possible drawback to this method: The destination path will contain the full path of the source. For instance, if the source root is C:\a\b\c and it contains a folder called Search_Term, and we wan’t the destination to be D:\, when we run the script, the destination will contain D:\a\b\c\Search_Term, which may not be the goal. ** ** In the end, I don’t think this is getting any better results the my original line. The 2NUL is just hiding the failures. ** ** Thanks for the script though, it was fun to digest J ** ** *From:* Andrew S. Baker [mailto:asbz...@gmail.com] *Sent:* Wednesday, July 20, 2011 3:06 PM *To:* NT System Admin Issues *Subject:* Re: file searching and copying ** ** How long are the paths? There are other ways to handle this, btw... Try the following snippet. It should handle long folders even if Windows complains about them @echo off SETLOCAL ENABLEDELAYEDEXPANSION SET @SOURCE=%SystemDrive% SET @DEST=D:\SomePlace SET @FIND=PrivacIE :Main for /f tokens=* %%v in ('dir /ad /b /s %@SOURCE%\*.* 2^NUL ^| FIND /I %@FIND%') do ( SET @DIR=%%~fpv ECHO. ECHO SOURCE: !@DIR! ECHO DEST: %@DEST%\%%~pv PUSHD !@DIR! echo XCOPY *.* %@DEST%%%~pv /S /E /R /Y ECHO. POPD ) ** ** ** ** :ExitBatch ENDLOCAL *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market…* On Wed, Jul 20, 2011 at 2:24 PM, Jeff Bunting bunting.j...@gmail.com wrote: Thanks all. Scott's suggestion is close and at least got me pointed in the right direction. Some of the paths are too long for DIR which throws a wrench in the works, so I'm going to have to rely on windows search for now. Powershell, unfortunately, currently isn't an option. Jeff On Wed, Jul 20, 2011 at 12:23 PM, Andrew S. Baker asbz...@gmail.com wrote: Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. ** ** *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market…* On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.edu wrote: For /f “tokens=*” %i in (‘dir *WORDS_TO_SEARCH* /s/a/b/ad’) do robocopy /mir “%i” DESTINATION_PATH This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. *From:* Jeff Bunting [mailto:bunting.j...@gmail.com] *Sent:* Wednesday, July 20, 2011 11:01 AM *To:* NT System Admin Issues *Subject:* file searching and copying I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy
Re: file searching and copying
Thanks much Andrew, your script was helpful indeed! Jeff On Thu, Jul 21, 2011 at 8:53 AM, Andrew S. Baker asbz...@gmail.com wrote: Hey, Scott 1. I left it there so the IP could see it run and decide how to use the data. 2. Possibly, but it was quick and dirty. Doesn't hurt with the p 3. Yes it does, and I forgot to remove that. Interestingly enough, it only causes a problem undoubtedly after the drive letter. Elsewhere in the path, it works just fine. 4. Good catch 5. Yes, but you have to do it all on one line. I separate the commands with a single within the parentheses The goal was to give him enough data to decide hour to implement it for his environment. -ASB: http://about.me/Andrew.S.Baker Sent from my Motorola Droid On Jul 20, 2011 7:50 PM, Crawford, Scott crawfo...@evangel.edu wrote: ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: file searching and copying
+1 Regards, Michael B. Smith Consultant and Exchange MVP http://TheEssentialExchange.com From: Andrew S. Baker [mailto:asbz...@gmail.com] Sent: Thursday, July 21, 2011 10:53 AM To: NT System Admin Issues Subject: Re: file searching and copying /E implies /S Out of habit I put them both, all the time. ASB http://about.me/Andrew.S.Baker Harnessing the Advantages of Technology for the SMB market... On Thu, Jul 21, 2011 at 10:37 AM, Jeff Bunting bunting.j...@gmail.commailto:bunting.j...@gmail.com wrote: I thought the /s /e was redundant when I first saw it too. The xcopy docs differ on the usage however: From Help and Support Center docs: /s Copies directories and subdirectories, unless they are empty. If you omit /s, xcopy works within a single directory. /e Copies all subdirectories, even if they are empty. Use /e with the /s and /t command-line options. command line (xcopy /?) /S Copies directories and subdirectories except empty ones. /E Copies directories and subdirectories, including empty ones. Same as /S /E. May be used to modify /T. On Wed, Jul 20, 2011 at 7:49 PM, Crawford, Scott crawfo...@evangel.edumailto:crawfo...@evangel.edu wrote: Nice to see pushd and popd making an appearance :) Few nits and questions, just to make sure I'm not missing something: 1. The echo in front of xcopy shouldn't be there. I'm sure it's just there for troubleshooting and left as an oversight. The /s /e is redundant, right? 2. I'm not very practiced with the enhanced ~ substitution, but couldn't the SET @DIR=%%~fpv line omit the p? 3. I think the ECHO DEST: %@DEST%\%%~pv line has an extra \ 4. I think the xcopy's destination parameter (%@DEST%%%~pv) needs to be %@DEST%%%~pnv. Without it, the files get copied into the corresponding parent on the destination. 5. Is there any way to get the parentheses code blocks work from the command line or do they need to be inside of a .bat? I've tried stringing the commands together with , but met with limited success. Possible drawback to this method: The destination path will contain the full path of the source. For instance, if the source root is C:\a\b\c and it contains a folder called Search_Term, and we wan't the destination to be D:\, when we run the script, the destination will contain D:\a\b\c\Search_Term, which may not be the goal. In the end, I don't think this is getting any better results the my original line. The 2NUL is just hiding the failures. Thanks for the script though, it was fun to digest :) From: Andrew S. Baker [mailto:asbz...@gmail.commailto:asbz...@gmail.com] Sent: Wednesday, July 20, 2011 3:06 PM To: NT System Admin Issues Subject: Re: file searching and copying How long are the paths? There are other ways to handle this, btw... Try the following snippet. It should handle long folders even if Windows complains about them @echo off SETLOCAL ENABLEDELAYEDEXPANSION SET @SOURCE=%SystemDrive% SET @DEST=D:\SomePlace SET @FIND=PrivacIE :Main for /f tokens=* %%v in ('dir /ad /b /s %@SOURCE%\*.*mailto:%25@SOURCE%25%5C*.* 2^NUL ^| FIND /I %@FIND%') do ( SET @DIR=%%~fpv ECHO. ECHO SOURCE: !@DIR! ECHO DEST: %@DEST%\%%~pv PUSHD !@DIR! echo XCOPY *.* %@DEST%%%~pv /S /E /R /Y ECHO. POPD ) :ExitBatch ENDLOCAL ASB http://about.me/Andrew.S.Baker Harnessing the Advantages of Technology for the SMB market... On Wed, Jul 20, 2011 at 2:24 PM, Jeff Bunting bunting.j...@gmail.commailto:bunting.j...@gmail.com wrote: Thanks all. Scott's suggestion is close and at least got me pointed in the right direction. Some of the paths are too long for DIR which throws a wrench in the works, so I'm going to have to rely on windows search for now. Powershell, unfortunately, currently isn't an option. Jeff On Wed, Jul 20, 2011 at 12:23 PM, Andrew S. Baker asbz...@gmail.commailto:asbz...@gmail.com wrote: Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. ASB http://about.me/Andrew.S.Baker Harnessing the Advantages of Technology for the SMB market... On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.edumailto:crawfo...@evangel.edu wrote: For /f tokens=* %i in ('dir *WORDS_TO_SEARCH* /s/a/b/ad') do robocopy /mir %i DESTINATION_PATH This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. From: Jeff Bunting [mailto:bunting.j...@gmail.commailto:bunting.j...@gmail.com] Sent: Wednesday, July 20, 2011 11:01 AM To: NT System Admin Issues Subject: file searching and copying I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff
RE: file searching and copying
Powershell! What's an example of your need? From: Jeff Bunting [mailto:bunting.j...@gmail.com] Sent: Wednesday, July 20, 2011 10:01 AM To: NT System Admin Issues Subject: file searching and copying I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: file searching and copying
For /f tokens=* %i in ('dir *WORDS_TO_SEARCH* /s/a/b/ad') do robocopy /mir %i DESTINATION_PATH This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. From: Jeff Bunting [mailto:bunting.j...@gmail.com] Sent: Wednesday, July 20, 2011 11:01 AM To: NT System Admin Issues Subject: file searching and copying I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: file searching and copying
You're going to have to script that, certainly. You could use robocopy or xcopy or do the whole thing in powershell, but no native tool provides the logic you want without some form of scripting. For instance, assuming that you were going to start in the C:\TEMP folder, and search for something: @echo off SETLOCAL ENABLEDELAYEDEXPANSION for /f tokens=* %%v in ('dir /ad /b /s C:\Temp\*.*' ^| FIND /I something) do ( SET @DIR=%~fpv ECHO Copying !@DIR! XCOPY !@DIR! D:\SomeDestination /S /E /R /Y ) * * *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market… * On Wed, Jul 20, 2011 at 12:00 PM, Jeff Bunting bunting.j...@gmail.comwrote: I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: file searching and copying
Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. * * *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market… * On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.eduwrote: For /f “tokens=*” %i in (‘dir *WORDS_TO_SEARCH* /s/a/b/ad’) do robocopy /mir “%i” DESTINATION_PATH ** ** This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. ** ** *From:* Jeff Bunting [mailto:bunting.j...@gmail.com] *Sent:* Wednesday, July 20, 2011 11:01 AM *To:* NT System Admin Issues *Subject:* file searching and copying ** ** I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: file searching and copying
Thx I'd also note that the /mir switch may not be exactly the option you want with robocopy, but that will copy the whole folder tree, deleting files at the destination if they're not at the source. From: Andrew S. Baker [mailto:asbz...@gmail.com] Sent: Wednesday, July 20, 2011 11:23 AM To: NT System Admin Issues Subject: Re: file searching and copying Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. ASB http://about.me/Andrew.S.Baker Harnessing the Advantages of Technology for the SMB market... On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.edumailto:crawfo...@evangel.edu wrote: For /f tokens=* %i in ('dir *WORDS_TO_SEARCH* /s/a/b/ad') do robocopy /mir %i DESTINATION_PATH This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. From: Jeff Bunting [mailto:bunting.j...@gmail.commailto:bunting.j...@gmail.com] Sent: Wednesday, July 20, 2011 11:01 AM To: NT System Admin Issues Subject: file searching and copying I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: file searching and copying
Thanks all. Scott's suggestion is close and at least got me pointed in the right direction. Some of the paths are too long for DIR which throws a wrench in the works, so I'm going to have to rely on windows search for now. Powershell, unfortunately, currently isn't an option. Jeff On Wed, Jul 20, 2011 at 12:23 PM, Andrew S. Baker asbz...@gmail.com wrote: Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. * * *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market… * On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.eduwrote: For /f “tokens=*” %i in (‘dir *WORDS_TO_SEARCH* /s/a/b/ad’) do robocopy /mir “%i” DESTINATION_PATH ** ** This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. ** ** *From:* Jeff Bunting [mailto:bunting.j...@gmail.com] *Sent:* Wednesday, July 20, 2011 11:01 AM *To:* NT System Admin Issues *Subject:* file searching and copying ** ** I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: file searching and copying
yeah, I figured that one out pretty quickly. (right after a puzzled 'wh?' when there was only one file copied) :-) DIR wasn't giving me all of the files, so had to abandon it for now, but thanks for the idea. Jeff On Wed, Jul 20, 2011 at 1:28 PM, Crawford, Scott crawfo...@evangel.eduwrote: Thx ** ** I’d also note that the /mir switch may not be exactly the option you want with robocopy, but that will copy the whole folder tree, deleting files at the destination if they’re not at the source. ** ** *From:* Andrew S. Baker [mailto:asbz...@gmail.com] *Sent:* Wednesday, July 20, 2011 11:23 AM *To:* NT System Admin Issues *Subject:* Re: file searching and copying ** ** Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market…* On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.edu wrote: For /f “tokens=*” %i in (‘dir *WORDS_TO_SEARCH* /s/a/b/ad’) do robocopy /mir “%i” DESTINATION_PATH This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. *From:* Jeff Bunting [mailto:bunting.j...@gmail.com] *Sent:* Wednesday, July 20, 2011 11:01 AM *To:* NT System Admin Issues *Subject:* file searching and copying I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ** ** ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: file searching and copying
So, you are searching a whole tree? Seems like you'd end up with duplicates if the search terms show up at one level and a sublevel. If you're just searching one level, you might try subst to shorten the paths. For instance, if your base is c:\long\path\to\root, you can run subst x: c:\long\path\to\root to trim a bunch off the length. From: Jeff Bunting [mailto:bunting.j...@gmail.com] Sent: Wednesday, July 20, 2011 1:25 PM To: NT System Admin Issues Subject: Re: file searching and copying Thanks all. Scott's suggestion is close and at least got me pointed in the right direction. Some of the paths are too long for DIR which throws a wrench in the works, so I'm going to have to rely on windows search for now. Powershell, unfortunately, currently isn't an option. Jeff On Wed, Jul 20, 2011 at 12:23 PM, Andrew S. Baker asbz...@gmail.commailto:asbz...@gmail.com wrote: Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. ASB http://about.me/Andrew.S.Baker Harnessing the Advantages of Technology for the SMB market... On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.edumailto:crawfo...@evangel.edu wrote: For /f tokens=* %i in ('dir *WORDS_TO_SEARCH* /s/a/b/ad') do robocopy /mir %i DESTINATION_PATH This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. From: Jeff Bunting [mailto:bunting.j...@gmail.commailto:bunting.j...@gmail.com] Sent: Wednesday, July 20, 2011 11:01 AM To: NT System Admin Issues Subject: file searching and copying I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
Re: file searching and copying
How long are the paths? There are other ways to handle this, btw... Try the following snippet. It should handle long folders even if Windows complains about them @echo off SETLOCAL ENABLEDELAYEDEXPANSION SET @SOURCE=%SystemDrive% SET @DEST=D:\SomePlace SET @FIND=PrivacIE :Main for /f tokens=* %%v in ('dir /ad /b /s %@SOURCE%\*.* 2^NUL ^| FIND /I %@FIND%') do ( SET @DIR=%%~fpv ECHO. ECHO SOURCE: !@DIR! ECHO DEST: %@DEST%\%%~pv PUSHD !@DIR! echo XCOPY *.* %@DEST%%%~pv /S /E /R /Y ECHO. POPD ) :ExitBatch ENDLOCAL * * *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market… * On Wed, Jul 20, 2011 at 2:24 PM, Jeff Bunting bunting.j...@gmail.comwrote: Thanks all. Scott's suggestion is close and at least got me pointed in the right direction. Some of the paths are too long for DIR which throws a wrench in the works, so I'm going to have to rely on windows search for now. Powershell, unfortunately, currently isn't an option. Jeff On Wed, Jul 20, 2011 at 12:23 PM, Andrew S. Baker asbz...@gmail.comwrote: Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. * * *ASB* *http://about.me/Andrew.S.Baker* *Harnessing the Advantages of Technology for the SMB market… * On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.eduwrote: For /f “tokens=*” %i in (‘dir *WORDS_TO_SEARCH* /s/a/b/ad’) do robocopy /mir “%i” DESTINATION_PATH ** ** This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. ** ** *From:* Jeff Bunting [mailto:bunting.j...@gmail.com] *Sent:* Wednesday, July 20, 2011 11:01 AM *To:* NT System Admin Issues *Subject:* file searching and copying ** ** I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin
RE: file searching and copying
Nice to see pushd and popd making an appearance :) Few nits and questions, just to make sure I'm not missing something: 1. The echo in front of xcopy shouldn't be there. I'm sure it's just there for troubleshooting and left as an oversight. The /s /e is redundant, right? 2. I'm not very practiced with the enhanced ~ substitution, but couldn't the SET @DIR=%%~fpv line omit the p? 3. I think the ECHO DEST: %@DEST%\%%~pv line has an extra \ 4. I think the xcopy's destination parameter (%@DEST%%%~pv) needs to be %@DEST%%%~pnv. Without it, the files get copied into the corresponding parent on the destination. 5. Is there any way to get the parentheses code blocks work from the command line or do they need to be inside of a .bat? I've tried stringing the commands together with , but met with limited success. Possible drawback to this method: The destination path will contain the full path of the source. For instance, if the source root is C:\a\b\c and it contains a folder called Search_Term, and we wan't the destination to be D:\, when we run the script, the destination will contain D:\a\b\c\Search_Term, which may not be the goal. In the end, I don't think this is getting any better results the my original line. The 2NUL is just hiding the failures. Thanks for the script though, it was fun to digest :) From: Andrew S. Baker [mailto:asbz...@gmail.com] Sent: Wednesday, July 20, 2011 3:06 PM To: NT System Admin Issues Subject: Re: file searching and copying How long are the paths? There are other ways to handle this, btw... Try the following snippet. It should handle long folders even if Windows complains about them @echo off SETLOCAL ENABLEDELAYEDEXPANSION SET @SOURCE=%SystemDrive% SET @DEST=D:\SomePlace SET @FIND=PrivacIE :Main for /f tokens=* %%v in ('dir /ad /b /s %@SOURCE%\*.*mailto:%25@SOURCE%25\*.* 2^NUL ^| FIND /I %@FIND%') do ( SET @DIR=%%~fpv ECHO. ECHO SOURCE: !@DIR! ECHO DEST: %@DEST%\%%~pv PUSHD !@DIR! echo XCOPY *.* %@DEST%%%~pv /S /E /R /Y ECHO. POPD ) :ExitBatch ENDLOCAL ASB http://about.me/Andrew.S.Baker Harnessing the Advantages of Technology for the SMB market... On Wed, Jul 20, 2011 at 2:24 PM, Jeff Bunting bunting.j...@gmail.commailto:bunting.j...@gmail.com wrote: Thanks all. Scott's suggestion is close and at least got me pointed in the right direction. Some of the paths are too long for DIR which throws a wrench in the works, so I'm going to have to rely on windows search for now. Powershell, unfortunately, currently isn't an option. Jeff On Wed, Jul 20, 2011 at 12:23 PM, Andrew S. Baker asbz...@gmail.commailto:asbz...@gmail.com wrote: Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. ASB http://about.me/Andrew.S.Baker Harnessing the Advantages of Technology for the SMB market... On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.edumailto:crawfo...@evangel.edu wrote: For /f tokens=* %i in ('dir *WORDS_TO_SEARCH* /s/a/b/ad') do robocopy /mir %i DESTINATION_PATH This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. From: Jeff Bunting [mailto:bunting.j...@gmail.commailto:bunting.j...@gmail.com] Sent: Wednesday, July 20, 2011 11:01 AM To: NT System Admin Issues Subject: file searching and copying I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana...@lyris.sunbeltsoftware.commailto:listmana...@lyris.sunbeltsoftware.com with the body: unsubscribe ntsysadmin ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage
RE: file searching and copying
Ok, my last post on this todayI think :) for /f tokens=* %i in ('dir * WORDS_TO_SEARCH * /s/ad/b') do robocopy /mir %i DESTINATION_PATH\%~pni Adding the %~pni will prevent every copy from overwriting the previous. This will recreate your entire tree at the destination similar to Andrew's script below which may or may not be what you want. You can change it to \%~ni so that each source directory gets copied to the root of the destination, but any duplicates will overwrite each other so /mir may not be the best option. As far as paths that are too long, robocopy will handle paths up to 32,000 characters, but the dir command is the limiting factor here. In any case, you should be able to see the paths that don't get copied and do those manually, but the others should work. From: Crawford, Scott [mailto:crawfo...@evangel.edu] Sent: Wednesday, July 20, 2011 6:50 PM To: NT System Admin Issues Subject: RE: file searching and copying Nice to see pushd and popd making an appearance :) Few nits and questions, just to make sure I'm not missing something: 1. The echo in front of xcopy shouldn't be there. I'm sure it's just there for troubleshooting and left as an oversight. The /s /e is redundant, right? 2. I'm not very practiced with the enhanced ~ substitution, but couldn't the SET @DIR=%%~fpv line omit the p? 3. I think the ECHO DEST: %@DEST%\%%~pv line has an extra \ 4. I think the xcopy's destination parameter (%@DEST%%%~pv) needs to be %@DEST%%%~pnv. Without it, the files get copied into the corresponding parent on the destination. 5. Is there any way to get the parentheses code blocks work from the command line or do they need to be inside of a .bat? I've tried stringing the commands together with , but met with limited success. Possible drawback to this method: The destination path will contain the full path of the source. For instance, if the source root is C:\a\b\c and it contains a folder called Search_Term, and we wan't the destination to be D:\, when we run the script, the destination will contain D:\a\b\c\Search_Term, which may not be the goal. In the end, I don't think this is getting any better results the my original line. The 2NUL is just hiding the failures. Thanks for the script though, it was fun to digest :) From: Andrew S. Baker [mailto:asbz...@gmail.com]mailto:[mailto:asbz...@gmail.com] Sent: Wednesday, July 20, 2011 3:06 PM To: NT System Admin Issues Subject: Re: file searching and copying How long are the paths? There are other ways to handle this, btw... Try the following snippet. It should handle long folders even if Windows complains about them @echo off SETLOCAL ENABLEDELAYEDEXPANSION SET @SOURCE=%SystemDrive% SET @DEST=D:\SomePlace SET @FIND=PrivacIE :Main for /f tokens=* %%v in ('dir /ad /b /s %@SOURCE%\*.*mailto:%25@SOURCE%25\*.* 2^NUL ^| FIND /I %@FIND%') do ( SET @DIR=%%~fpv ECHO. ECHO SOURCE: !@DIR! ECHO DEST: %@DEST%\%%~pv PUSHD !@DIR! echo XCOPY *.* %@DEST%%%~pv /S /E /R /Y ECHO. POPD ) :ExitBatch ENDLOCAL ASB http://about.me/Andrew.S.Baker Harnessing the Advantages of Technology for the SMB market... On Wed, Jul 20, 2011 at 2:24 PM, Jeff Bunting bunting.j...@gmail.commailto:bunting.j...@gmail.com wrote: Thanks all. Scott's suggestion is close and at least got me pointed in the right direction. Some of the paths are too long for DIR which throws a wrench in the works, so I'm going to have to rely on windows search for now. Powershell, unfortunately, currently isn't an option. Jeff On Wed, Jul 20, 2011 at 12:23 PM, Andrew S. Baker asbz...@gmail.commailto:asbz...@gmail.com wrote: Good one, Scott. Jeff, remember to add a % to each variable if used in a batch file, vs the command line. ASB http://about.me/Andrew.S.Baker Harnessing the Advantages of Technology for the SMB market... On Wed, Jul 20, 2011 at 12:13 PM, Crawford, Scott crawfo...@evangel.edumailto:crawfo...@evangel.edu wrote: For /f tokens=* %i in ('dir *WORDS_TO_SEARCH* /s/a/b/ad') do robocopy /mir %i DESTINATION_PATH This will search a folder tree for directorys. Change the dir command to eliminate the /s if you only want to search the root. From: Jeff Bunting [mailto:bunting.j...@gmail.commailto:bunting.j...@gmail.com] Sent: Wednesday, July 20, 2011 11:01 AM To: NT System Admin Issues Subject: file searching and copying I'm attempting to search for particular words in a directory name (must use wildcards!), and, if found, copy the the directory tree while maintaining its structure to another directory. Are there any native tools (or reskit like robocopy) that can accomplish this somewhat easily? thanks, Jeff ~ Finally, powerful endpoint security that ISN'T a resource hog! ~ ~ http://www.sunbeltsoftware.com/Business/VIPRE-Enterprise/ ~ --- To manage subscriptions click here: http://lyris.sunbelt-software.com/read/my_forums/ or send an email to listmana