

InterviewSolution
Saved Bookmarks
1. |
Solve : Help me in my Batch Script? |
Answer» <html><body><p>I have a batch script which copies the targeted files from drives, for example if I want all .doc to be copied from C Drive it copies all, the <a href="https://interviewquestions.tuteehub.com/tag/thing-25656" style="font-weight:bold;" target="_blank" title="Click to know more about THING">THING</a> is I need it to copy 20, or <a href="https://interviewquestions.tuteehub.com/tag/10-236933" style="font-weight:bold;" target="_blank" title="Click to know more about 10">10</a> files not full .doc from C drive.<br/><br/>Can anyone help me in this please.<br/><br/>Here is the code for the script.<br/> Code: <a>[Select]</a>echo off<br/>SETLOCAL EnableDelayedExpansion<br/>set destfolder=D:\copiedjpegs<br/>set searchdrive="C:\"<br/>for /f "tokens=*" %%<a href="https://interviewquestions.tuteehub.com/tag/p-236832" style="font-weight:bold;" target="_blank" title="Click to know more about P">P</a> in ('dir %searchdrive%*.doc /s /b') do copy "%%P" %Desktop% Quote from: akki15623 on March <a href="https://interviewquestions.tuteehub.com/tag/12-241884" style="font-weight:bold;" target="_blank" title="Click to know more about 12">12</a>, 2010, 03:25:22 PM</p><blockquote>. . . for example if I want all .doc to be copied from C Drive it copies all, the thing is I need it to copy 20, or 10 files not full .doc from C drive.<br/></blockquote> <br/><br/>C:\batch>type akki.bat<br/> Code: <a>[Select]</a>echo off<br/>setLocal EnableDelayedExpansion<br/>set /a c=0<br/>set destfolder=<a href="https://interviewquestions.tuteehub.com/tag/e-236626" style="font-weight:bold;" target="_blank" title="Click to know more about E">E</a>:\copydoc\<br/><br/>for /f "delims==" %%i in ('dir c:\*.doc /s /b') do (<br/>echo %%~nxi<br/>set /a c+=1<br/><br/>echo c=!c!<br/>if !c! GTR 9 goto end<br/><br/>copy "%%i" %destfolder%<br/>)<br/>:end<br/><strong>Output:</strong><br/><br/>C:\batch>akki.bat<br/>longshot.doc<br/>c=1<br/> 1 file(s) copied.<br/>longshot.doc<br/>c=2<br/> 1 file(s) copied.<br/>ls.doc<br/>c=3<br/> 1 file(s) copied.<br/>winword.doc<br/>c=4<br/> 1 file(s) copied.<br/>winword2.doc<br/>c=5<br/> 1 file(s) copied.<br/>fractions.doc<br/>c=6<br/> 1 file(s) copied.<br/>third.doc<br/>c=7<br/> 1 file(s) copied.<br/>twothird.doc<br/>c=8<br/> 1 file(s) copied.<br/>What is My IP Address.doc<br/>c=9<br/> 1 file(s) copied.<br/>aarp081009.doc<br/>c=10<br/>C:\batch><br/><br/><br/>E:\copydoc>dir<br/> <br/> Directory of E:\copydoc<br/><br/>03/12/2010 06:18 PM .<br/>03/12/2010 06:18 PM ..<br/>10/23/2009 09:25 PM 20,480 fractions.doc<br/>03/06/2005 09:59 PM 4,195 longshot.doc<br/>03/06/2005 09:59 PM 4,195 ls.doc<br/>10/23/2009 08:44 PM 24,576 third.doc<br/>10/23/2009 08:45 PM 24,576 twothird.doc<br/>10/20/2009 11:27 AM 24,064 What is My IP Address.doc<br/>04/14/2008 06:00 AM 4,608 winword.doc<br/>04/14/2008 06:00 AM 1,769 winword2.doc<br/> 8 File(s) 108,463 bytes<br/> 2 Dir(s) 139,440,300,032 bytes free<br/><br/>E:\copydoc><br/> Quote from: greg on March 12, 2010, 05:24:21 PM<blockquote><br/>C:\batch>type akki.bat<br/> Code: <a>[Select]</a>echo off<br/>setLocal EnableDelayedExpansion<br/>set /a c=0<br/>set destfolder=E:\copydoc\<br/><br/>for /f "delims==" %%i in ('dir c:\*.doc /s /b') do (<br/>echo %%~nxi<br/>set /a c+=1<br/><br/>echo c=!c!<br/>if !c! GTR 9 goto end<br/><br/>copy "%%i" %destfolder%<br/>)<br/>:end</blockquote> <br/><br/>Thanks Greg, you saved my day.</body></html> | |