-1

I wanted to make a cmd-windows-backup-script for my four firefox profiles.

But I have a curious problem.

%%c and %%c in the set command have different values.

I think it's because the (...)

Any idea how I can fix this problem?

    cd /D "%appdata%\Mozilla\Firefox\Profiles"

    for /D %%c in (*) do (

        echo %%c            

        set source="%appdata%\Mozilla\Firefox\Profiles\%%c"
        set target="%appdata%\Mozilla\Firefox\Profiles\AutoBackup\%date%\%%c.7z"

        echo %source%
        echo %target%

        rem here is now my zip action planned, but source and target have always the same name

        timeout 5

    )
Marcus
  • 1
  • 1
  • @SomethingDark doesn't look like a dupe to me. The OP's problem has nothing to do with delayed expansion. – jwdonahue Feb 16 '18 at 03:06
  • 1
    @jwdonahue - he's setting variables inside of a code block and then asking why his variable values aren't what he expects them to be. That's the very definition of a delayed expansion problem. He just coincidentally happens to have a second problem that he hasn't found out about yet, which is the answer you posted. – SomethingDark Feb 16 '18 at 03:49
  • @SomethingDark, hmm... apologies. This is why I never use multi-line code blocks. – jwdonahue Feb 16 '18 at 04:01

1 Answers1

0

you need to use setlocal enabledelayedexpansion

@echo off
setlocal enabledelayedexpansion
cd /D "%appdata%\Mozilla\Firefox\Profiles"

for /D %%c in (*) do (

    echo %%c            

    set source="%appdata%\Mozilla\Firefox\Profiles\%%c"
    set target="%appdata%\Mozilla\Firefox\Profiles\AutoBackup\%date%\%%c.7z"

    echo !source!
    echo !target!
    timeout 5

)
endlocal

for more on delayedexpansion do from cmdline setlocal /?

Gerhard
  • 22,678
  • 7
  • 27
  • 43