batch-filecmdcommand-promptclip

Using CLIP command within a Batch File


I am trying to write a batch file to do the following:

  1. Copy a given file (drag and drop or through "send to" option) to a predefined network drive
  2. Build a file path string
  3. Copy the file path to the clipboard

Here is what I have so far:

@ECHO OFF
ECHO "%~1"
ECHO "Uploading File..."
COPY "%~1" "PATH_TO_NETWORK_DRIVE"
SET "path=PATH_TO_NETWORK_DRIVE"
SET "file=%~nx1"
SET "link=%path%%file%"
ECHO %link%> "I:\filepath.txt"
START "I:\filepath.txt"

The above works in so far as the file is copied to the correct location and the text file is created containing the path string. I'm only using an external text file and the START command above purely because I've hit a road block in getting the text file to copy to the clipboard, trying numerous variations of the CLIP command. I've tried:

ECHO %link%| clip

clip < "I:\filepath.txt"

type "I:\filepath.txt" | clip

None of the above are working for me, despite other threads on here suggesting that they should. Is there a limitation in using CLIP in a batch file? Is there any workaround to this? Any assistance I can get would be hugely appreciated :)


Solution

  • You're wiping out your system path with this statement, so your batch file probably can't find CLIP.EXE.

    SET "path=PATH_TO_NETWORK_DRIVE"
    

    Change it to mypath (or any other name):

    SET "mypath=PATH_TO_NETWORK_DRIVE"
    

    Also, change all of your references from %path% to %mypath%.