Echo variables with space

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
deniscalanca
Posts: 14
Joined: 26 Oct 2017 11:30

Echo variables with space

#1 Post by deniscalanca » 25 Jun 2024 09:03

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?

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Echo variables with space

#2 Post by Squashman » 25 Jun 2024 09:46

Code: Select all

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

Post Reply