Jump to content

Recommended Posts

Posted (edited)

OK, so I'm trying to move some information from people's "My Documents" but sadly those may sit on different locations so I'm trying to read the registry and creating a variable based on that, but it doesn't seem to be working.

Here's what I'm using:

FOR /F "tokens=2* delims=	 " %%A IN ('REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') DO SET PERSONAL=%%B
ECHO PERSONAL="%PERSONAL%"
CD %PERSONAL%

The echo command shows me the proper location, but when I attempt to change directory with that variable I get the following error message:

The system cannot find the path specified.

What am I doing wrong?!??!

Edited by TheReasonIFail

Posted

Try this:

ECHO OFF
FOR /F "tokens=3 delims= " %%A IN ('REG QUERY "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v Personal') DO SET PERSONAL="%%A"
SET PERSONAL

ECHO Expanding variable with CALL to SUBROUTINE
CALL :Expand_var %PERSONAL%

ECHO Expanding variable with CALL SET
CALL SET PERSONAL=%PERSONAL%
SET PERSONAL
ECHO CD %PERSONAL%

pause
GOTO :EOF

:Expand_var
ECHO CD %1
GOTO :EOF

;)

jaclaz

Posted

In a batch file (.bat or .cmd) the variables need two %%, in the command line (for testing) the variables only accept one %

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...