Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am currently using the following batch file to copy all word files on my hard drive to a specific folder:
md "c:\" 2>nul
for /f "delims=" %%a in (
'dir "c:\hello\*.doc" /b /s /a-d'
) do copy "%%a" "c:\newfolder" /-yI have deliberately enabled prompting as I want to ensure that no files are overwritten. I have a lot of these files and have to do this regularly so sitting typing “n enter” each time I am prompted is not in any way desirable!!!
Does anyone know how this could be written into the above batch file to automate the input of “n” then “enter”?

As ever, much depends on the OS.
=====================================
If at first you don't succeed, you're about average.M2

I'm not booted in DOS but I think this will do it. It'll preview what's to be done. Once you're satisfied, remove the ECHO from the FOR line.
::====================
@echo offset src=c:\files
set dest=d:\bakup
cd %src%for %%a in (*.txt) do echo if not exist %dest%\%%a copy %%a %dest%\
=====================================
If at first you don't succeed, you're about average.M2

Thanks for that, it does seem to work to a degree however I am somewhat new to batch files as I have only recently discovered their usefulness, it is also a long time since I used dos…..
I have modified the file as follows:
set src=c:\hello
set dest=c:\newfolder
cd %src%
for %%a in (*.doc) do echo if not exist %dest%\%%a copy %%a %dest%\how do I modify this to ensure that all documents in the sub directories in the src c:\hello are also copied?

You could set your copycmd env variable to /-y and in your original script you could try
) do echo n | copy "%%a" "c:\newfolder"

"Thanks for that, it does seem to work to a degree however I am somewhat new to batch files as I have only recently discovered their usefulness, it is also a long time since I used dos….."
Actually in XP you are not using MS-DOS but NT COMMAND PROMPT (CMD.EXE)

"that works like a dream!!!! thanks Garibaldi, simple yet effective!!!"
Thanks for coming back with that MalbyMalby. Once you're confident with your script you could add > NUL to the DO line in order not to output all the Copy queries to the screen or you could add >> path\filename to output the queries to a file in order to view them later.
Good luck.
Valerie.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |