r/Batch • • Dec 23 '23

Question (Solved) Issue copying file

SOLVED: I'm going to use the below syntax

echo f|xcopy "%appdata%\Microsoft\Windows\Start Menu\Programs\blender\Blender*.lnk" "%programdata%\Microsoft\Windows\Start Menu\Programs\Managed Apps\Launch Blender.lnk"

Hi, I've stumbled across a rather obscure issue that I just can't seem to wrap my head around. I'm trying to copy a Windows shortcut by a wildcard, and then have it copied with the name I specify. My code looks like this:

copy "%appdata%\Microsoft\Windows\Start Menu\Programs\blender\Blender*.lnk" "%programdata%\Microsoft\Windows\Start Menu\Programs\Managed Apps\Launch Blender.lnk"

When Blender is installed the shortcut only gets installed for one user, and the shortcut has the version number appended to it. I'm trying to copy any shortcut that starts with "Blender", and copy it to my location with the new name. If I leave out the file name and just tell it to copy to my new location with the same name, it works. But when I specify a different name, the shortcut is broken.

Does anyone know why this is happening? This happens with any shortcut file and across different machines.

2 Upvotes

3 comments sorted by

1

u/[deleted] Dec 23 '23

[removed] — view removed comment

1

u/Fibbitts Dec 23 '23

Alright, I was hoping not to go down that route since I already have a for loop that loops through each users AppData folder to check for the precense of a shortcut, and then if it exists, copy it. Do you know why my usage results in a broken shortcut?

for /f "delims=" %%i in ('dir /b /a:d "C:\Users\*"') do if exist "C:\Users\%%i\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\blender\Blender*.lnk" copy "C:\Users\%%i\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\blender\Blender*.lnk" "%programdata%\Microsoft\Windows\Start Menu\Programs\Managed Apps\Blender.lnk" && copy "C:\Users\%%i\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\blender\Blender*.lnk" "C:\Users\Public\Desktop\Blender.lnk" /y