Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: XCOPY problems with user input  (Read 4917 times)

0 Members and 1 Guest are viewing this topic.

KUKKA

    Topic Starter


    Newbie

    • Experience: Beginner
    • OS: Unknown
    XCOPY problems with user input
    « 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

    Geek-9pm


      Mastermind
    • Geek After Dark
    • Thanked: 1026
      • Gekk9pm bnlog
    • Certifications: List
    • Computer: Specs
    • Experience: Expert
    • OS: Windows 10
    Re: XCOPY problems with user input
    « Reply #1 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.

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: XCOPY problems with user input
    « Reply #2 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)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein