Computing.Net > Forums > Disk Operating System > Batch File: Automating repetitive..

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Batch File: Automating repetitive..

Reply to Message Icon

Name: malbymalby
Date: August 5, 2008 at 01:03:24 Pacific
OS: dos
CPU/Ram: 1g
Product: amd
Comment:

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" /-y

I 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”?



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: August 5, 2008 at 04:29:25 Pacific
Reply:

As ever, much depends on the OS.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: malbymalby
Date: August 5, 2008 at 05:06:14 Pacific
Reply:

Currnetly using XP but i would like this to work on 98, 2000 and vista if this is possible......


0

Response Number 3
Name: Mechanix2Go
Date: August 5, 2008 at 05:43:08 Pacific
Reply:

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 off

set 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


0

Response Number 4
Name: malbymalby
Date: August 5, 2008 at 08:02:11 Pacific
Reply:

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?


0

Response Number 5
Name: Valerie (by Garibaldi)
Date: August 5, 2008 at 14:59:53 Pacific
Reply:

You could set your copycmd env variable to /-y and in your original script you could try

) do echo n | copy "%%a" "c:\newfolder"


0

Related Posts

See More



Response Number 6
Name: malbymalby
Date: August 6, 2008 at 03:57:56 Pacific
Reply:

that works like a dream!!!! thanks Garibaldi, simple yet effective!!!


0

Response Number 7
Name: itguru
Date: August 6, 2008 at 22:37:12 Pacific
Reply:

"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)


0

Response Number 8
Name: Valerie (by Garibaldi)
Date: August 7, 2008 at 15:12:57 Pacific
Reply:

"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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch File: Automating repetitive..

Automate batch files www.computing.net/answers/dos/automate-batch-files/4052.html

Automate DOS batch File www.computing.net/answers/dos/automate-dos-batch-file/14507.html

batch file www.computing.net/answers/dos/batch-file/3808.html