Ali
Ali

Reputation: 167

Copy and paste files from one directory into current working directory

I'm trying to debug why i can't run this command

DOSKEY w-new=copy C:\utils\ticket_templates\wordpress\readme.txt "%cd%/readme.txt" /Y

I've tried both windows cmd as administrator and not

If i simply type C:\utils\ticket_templates\wordpress\readme.txt "%cd%/readme.txt" into the terminal it works but not if i use the w-new alias.

The w-new alias works inconsistently too. For example i can use it in /user/%USERPROFILE%/ dir but not in any of it's sub-directories.

I checked the file permissions of the destination and it's exactly the same as /user/%USEPROFILE%/

Any advice on debugging this is appreciated. Both source and destination are git repositories btw. As is /user/%USERPROFILE%/

Upvotes: 1

Views: 176

Answers (1)

dbenham
dbenham

Reputation: 130819

Your problem is %cd% is expanded when the w-new alias is defined, so the copy destination becomes constant - the current directory at the time of macro definition. You can see this by typing the following from the command line prompt:

doskey /macros

Also, you should not use / as a folder separator, use \ instead. The / often works, but not in all situations.

You can prevent %cd% from being expanded during definition by inserting a caret within the variable name:

DOSKEY w-new=copy C:\utils\ticket_templates\wordpress\readme.txt "%^cd%\readme.txt" /Y

But why provide any target at all? You are simply copying a file to the current directory, using the original file name - that is the default behavior of COPY when no destination is specified.

So your macro can simply be:

DOSKEY w-new=copy C:\utils\ticket_templates\wordpress\readme.txt

Upvotes: 1

Related Questions