0

I'm looking for a batch that look into folders that begins with "@" and then inside those folders have a subfolder named "Keys" copy a file.bikey to a static folder name "keys".

The for /d loop that I use apparently stops working due to a cd/goto commands inside.

Main
│   key-collector.bat
│
├───@folder_a
│   └───keys
│           a.txt
│
├───@folder_b
│   └───keys
│           b.txt
│
├───@folder_c
│   └───keys
│           c.txt
└───keys
    └───(Destination)

Current code:

@echo off
:start
set modsPath="C:\Exemple"
set keysPath="%modsPath%\keys"
for /d %%i in (@*) do (
    echo %%i
    copy /y %cd%\%%i\keys\*.txt %keysPath%
    ::cd %cd%\%%i\keys
    ::copy *.txt %keysPath%
    )
PAUSE>nul
exit
1
  • 3
    do not use an invalid label inside a code block. change :: to rem. Then on the cd command, why even cd? just copy the files from full path or pushd path and popd after the copy. Commented Oct 29, 2021 at 14:18

1 Answer 1

1

Few things:

  1. set the path with double quotes including the variable name i.e set "var=value"
  2. Do not use invalid labels :: inside a code block, instead use rem
  3. add double quotes to your paths for instance: copy /y "%cd%\%%i\keys\*.txt" "%keysPath%"
  4. use %%~fi for the full path instead of cd
@echo off
:start
set "modsPath=C:\Example"
set "keysPath=%modsPath%\keys"
for /d %%i in (@*) do (
    echo %%~fi
    copy /y "%%~fi\keys\*.txt" "%keysPath%"
    rem comments like this
    )
pause>nul
Sign up to request clarification or add additional context in comments.

3 Comments

It doesn't seems to understand the %%~fi, it returns: %~fi (from echo) and "Path not found"
Did you copy the code as is? please double check. %%~f is a valid expansion for a variable. see for /? from cmd
I mixed up my actual batch with my copy for testing, it works well, I really do appreciate your help. thank you

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.