Computer Hope

Microsoft => Microsoft DOS => Topic started by: KUKKA on June 11, 2012, 11:34:09 AM

Title: XCOPY problems with user input
Post by: KUKKA on June 11, 2012, 11:34:09 AM
Hi,

I am trying to copy only one file from multiple files with user prompt using XCOPY. If the user chooses 'y' it should copy into a target.txt file.

This is the script I am using

xcopy D:\source\*.*/p D:\Target.txt || goto error
But it asks me a file or directory. So I tried doing this.

echo F | xcopy xcopy D:\source\*.*/p D:\Target.txt || goto error

Now, it is not asking for the user input anymore. How can I prompt for user input by defaulting to a file?
Experts... Please help
Thanks
Title: Re: XCOPY problems with user input
Post by: Geek-9pm on June 11, 2012, 04:02:37 PM
It would help if you would explain what and why of the project.
Why would you only copy some files? What makes them different?
Are they in many directories? Why?
Are the files read only?
Do you want a minimal batch file few people can understand ?
Or do you want something that can later be updated by others?
A script file using Vb script would be an good chive.
But it can be done in batch.
One way is ton just divide the project into tasks. That is, a set of batch files that work as part of a whole.
Title: Re: XCOPY problems with user input
Post by: Sidewinder on June 12, 2012, 06:53:46 AM
As long as you pipe F to XCOPY, you can use the COPY utility and write out the code in longhand:

Code: [Select]
@echo off
setlocal enabledelayedexpansion
for /r d:\source %%v in (*.*) do (
  set /p prompt=Copy %%v (y/n^):
  if /i !prompt! EQU y copy /-Y "%%v" d:\target.txt
)

If you can, replace the SET statement with CHOICE so you can better filter the responses.

 8)