0

I have different users that have name with space and no space : John Doe, Jane Susy I tried typing %APPDATA% in command prompt, and all i get is John / Jane.

How should i script my batch/cmd file, so it supports folder with spaces?

Copy /y %APPDATA%\Folder\Templates\abc.txt %APPDATA%\Folder\Templates\FoldABC >nul

when i use echo %AppData% i get the full name John Doe / Jane Susy. When i just type %AppData% , i get John / Jane

I am trying to do the following:

if exist %APPDATA%\Folder\Templates\abc.txt (
   Copy /y %APPDATA%\Folder\Templates\abc.txt %APPDATA%\Folder\Templates\FoldABC >nul
)

Here is the error i get :

if exist C:\Users\John Doe\AppData\Roaming\Microsoft\Templates\abc.txt(
'Doe\AppData\Roaming\Folder\Templates\abc.txt' is not recognized as an internal or external command, operable program or batch file. 
2
  • Appdata is underneath a User and every User has an Appdata. What (in words) are you trying to do? Commented Mar 25, 2022 at 23:35
  • You would normally encapsulate the path in double quotations, however that generally shouldn't be needed with default environment variables. What does echo %AppData% return? If double quotes doesn't work, try %UserProfile%\AppData\Roaming, otherwise you could echo the %UserName% within the path, but that shouldn't be necessary Commented Mar 26, 2022 at 0:22

1 Answer 1

1

Put every path with spaces between quotes:

Copy /y "%APPDATA%\Folder\Templates\abc.txt" "%APPDATA%\Folder\Templates\FoldABC" >nul
2
  • Great, it works on the if statements and also the command. Thanks Commented Mar 26, 2022 at 1:27
  • Glad I could help Commented Mar 26, 2022 at 2:26

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.