Friday, September 18, 2015

[CMD] PUSHD to path in clipboard

I use WinClip to get things in and out of the clipboard when doing stuff on the command line. (I grew up on CP/M, MP/M II and VAX VMS, so command line is usually where it's at for me.)

Occasionally, I have a path in the clipboard that I want to use as the target for a CD (or, more often, a PUSHD). I just cooked up the following .CMD script using WinClip. It uses the /F qualifier on the FOR command to iterate through the stdout of winclip -p and PUSHD to what it finds.

So what happens, you may ask, if the clipboard contains more than one line? If the paths are fully qualified then you end up in the folder defined by the last line. Otherwise, you end up in the folder defined by the first line and you see a pile of error messages about not being able to find the subsequent folders.
@echo off
 for /f "delims==" %%f in ('winclip -p') do pushd %%f
Enjoy! If you want to amplify the script to better handle unforeseen inputs, go right ahead. Share the result here if you feel so inclined.

© Copyright Bruce M. Axtens, 2015

No comments: