0

batch-file

I am a newbie to batch scripting. I was writing a script which gets a value from a registry key in windows. I am using a for loop

for /f "tokens=1*" %%A in ('reg query HKLM\Software\CDupe\ZIB\  /v BackupSetLocation' ) do SET path_temp=%%B
for /f "tokens=1*" %%A in ("%path_temp%") do SET BackupSet_Path=%%B

From this 2 for loops , I get the Value for the registry key BackupSetLocation.

The value I get when I echo %BackupSet_Path% is C:\ProgramData\CDupe\CDupe Cloud Backup(x64)\zcb\conf.

Problem is :

Now from the BackupSet_Path I want to extract only

C:\ProgramData\CDupe\CDupe Cloud Backup(x64)\ .

I tried this

for /f "tokens=1*" %%A in ('reg query HKLM\Software\CDupe\ZIB\ /v BackupSetLocation' ) do SET path_temp=%%B
for /f "tokens=1-4" %%A in ("%path_temp%") do SET BackupSet_Path=%%B

giving tokens = 1-4 , I get only C:\ProgramData\CDupe\CDupe

because there are whitespaces between "CDupe Cloud Backup(x64)".

Can anyone please tell me how to ignore those spaces and get this string

C:\ProgramData\CDupe\CDupe Cloud Backup(x64)\

Thanks for your time.

1

1 Answer 1

2
for /f "tokens=1*" %%A in ('reg query HKLM\Software\CDupe\ZIB\ /v BackupSetLocation' ) do SET path_temp=%%B
for /f "tokens=1-4 delims=\" %%A in ("%path_temp%") do SET BackupSet_Path=%%A\%%B\%%C\%%D\
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.