Jump to content

Batch file "Variable" issue


TheReasonIFail

Recommended Posts

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
Link to comment
Share on other sites


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

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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