Page 1 of 1

Echo variables with space

Posted: 25 Jun 2024 09:03
by deniscalanca
Hi, I'm trying to create a script to remove desktop shortcuts via GPO, I have the following code:

@echo off

set "shortcut=Adobe Acrobat.lnk Firefox.lnk Google Chrome.lnk Google Earth Pro.lnk"

for /d %%a in (%shortcut%) do (
echo %%a
)

Which is returning to me as follows:

Adobe
Acrobat.lnk
Firefox.lnk
Google
Chrome.lnk
Google
Earth
Pro.lnk

When in fact I needed it to come back to me as follows:

Adobe Acrobat.lnk
Firefox.lnk
Google Chrome.lnk
Google Earth Pro.lnk

The problem is that I can't print the full name that contains spaces, does anyone know how I could do this?

Re: Echo variables with space

Posted: 25 Jun 2024 09:46
by Squashman

Code: Select all

set "shortcut="Adobe Acrobat.lnk" "Firefox.lnk" "Google Chrome.lnk" "Google Earth Pro.lnk""
for %%G in (%shortcut%) do echo "%%~G"