1.

Solve : Batch file to copy files but not copy the batch file??

Answer» <html><body><p>Hi,<br/><br/>I have a very simple <a href="https://interviewquestions.tuteehub.com/tag/batch-893737" style="font-weight:bold;" target="_blank" title="Click to know more about BATCH">BATCH</a> file script to copy files in the current folder to another folder, but it also copies the actual .bat file. How can I <a href="https://interviewquestions.tuteehub.com/tag/exclude-979002" style="font-weight:bold;" target="_blank" title="Click to know more about EXCLUDE">EXCLUDE</a> the .bat file from also being copied?<br/><br/>here is what I have so far:<br/><br/>copy /-Y *.xml F:\\Test<br/>Exit<br/><br/>I tried this:<br/><br/>except *.bat copy /-Y *.xml F:\\Test<br/>Exit<br/><br/>with and without brackets but it does not work.<br/><br/>Any help <a href="https://interviewquestions.tuteehub.com/tag/would-3285927" style="font-weight:bold;" target="_blank" title="Click to know more about WOULD">WOULD</a> be appreciated.<br/>Jaime<br/><br/><br/>The simple way is to have the batch file itself in another directory.<br/>Let's say your stuff in in D:STUFF <br/>and the bat file name MYBAT.BAT is in D:\BAT<br/>then  go into D:STUFF directory  and give the command<br/>d:\bat\mybat<br/>Which will only operate on files in the current directory and sub directories.<br/><br/><br/>Sounds <a href="https://interviewquestions.tuteehub.com/tag/like-537196" style="font-weight:bold;" target="_blank" title="Click to know more about LIKE">LIKE</a> a good workaround, but I would like for it to send files from the current dir. rather than pull files from the current dir.<br/><br/>The target folder is a watched folder where all files in it are pulled into a translations program and automatically added to a <a href="https://interviewquestions.tuteehub.com/tag/translation-247002" style="font-weight:bold;" target="_blank" title="Click to know more about TRANSLATION">TRANSLATION</a> workflow project. So I do want to avoid adding any files to the watched folder that do not belong there.<br/><br/>Jaime<br/>If you use the copy command with the *.xml filemask then only files with extension .xml will be copied, and files with the extension .bat (or any other extension except .xml) will be ignored. Check your code.<br/><br/><br/>Yes, sorry, I meant to write *.* so as to copy all files in the directory.<br/><br/>Thanks,<br/>Jaime<br/>You can use a FOR loop and DIR to list the files to copy and skip the batch file's own name (which is %0) (that is a ZERO)<br/><br/> Code: <a>[Select]</a>echo off<br/>for /f "delims=" %%A in ('dir /b /a-d') do if not "%%A"=="%0" copy /-Y "%%A" F:\\Test</p></body></html>


Discussion

No Comment Found