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

Batch File: Automating repetitive..

Reply to Message Icon

Original Message
Name: malbymalby
Date: August 5, 2008 at 01:03:24 Pacific
Subject: Batch File: Automating repetitive..
OS: dos
CPU/Ram: 1g
Model/Manufacturer: 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”?


Report Offensive Message For Removal


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

As ever, much depends on the OS.


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

M2


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal

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

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?


Report Offensive Follow Up For Removal

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

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

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


Report Offensive Follow Up For Removal


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

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


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal

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

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


Report Offensive Follow Up For Removal






Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch File: Automating repetitive..

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software




Have you ever used OpenOffice?

Yes, as my main suite.
Yes, occationally.
Yes, but only once.
No, never.


View Results

Poll Finishes In 3 Days.
Discuss in The Lounge