0

I try to export all of my wiki into .docx file using pandoc. So I have created a .bat script. I have a file containing all of my url I want to export "liste_de_documents.txt" containing one string per line like :

hadoop:hadoop_-_hdfs_-_afficher_les_fichiers_avec_un_replica_inferieur_a_3
certificats:certificats_-_faq

I have this variable :

set "url=http://localhost:8800/doku.php?id="

I try to export my documentation and I need to do the concatenation of thoses 2 variables, but I always get an empry variable %downloadurl% as result :

setlocal enabledelayedexpansion
for /F "tokens=*" %%A in (liste_de_documents.txt) do (
    set downloadurl="%url%%%A"
    ECHO %url%
    ECHO %%A
    ECHO %downloadurl%
    ::C:\Z_owncloud\Logiciels_portables\Logiciels_portables_installes\pandoc-2.3-windows-x86_64\pandoc.exe -f html  "%url%%%A"  -o "C:\Users\user\Downloads\EXPORT_AUTOMATIQUE_DE_LA_DOC_DU_WIKI\%downloadurl%.docx"


)

How can I do the contatenation of my variable %url% and %%A into %downloadurl% please ?

Regards,

A.

Antoine
  • 355
  • 2
  • 12
  • 4
    you need [delayed expansion](https://stackoverflow.com/a/30284028/2152082) – Stephan Oct 11 '18 at 15:16
  • 3
    One of the most commonly asked questions on this forum. See https://stackoverflow.com/questions/19121138/batch-file-for-loops-multiple-lines/19121310#19121310 – RGuggisberg Oct 11 '18 at 15:19
  • 1
    In this case delayed expansion is not really needed. Just use `%url%%%A` wherever `%downloadurl%` is currently used in command block executed by __FOR__ on each iteration. And read also answer on [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](https://stackoverflow.com/a/26388460/3074564) explaining the difference between `set variable="value"` and `set "variable=value"`. The latter is most often wrong as also in posted code. – Mofi Oct 11 '18 at 15:30
  • 1
    Agree that@Mofi suggestion is best for this case. You should check out the link I posted to understand why you code failed though. – RGuggisberg Oct 11 '18 at 15:35
  • And don't use the double colon as a comment inside a parentheses code block. You will get undesired results in your code execution. – Squashman Oct 11 '18 at 16:35
  • Oups, I paste a part of my code, but they already was the option setlocal enabledelayedexpansion. I update my question with this line – Antoine Oct 12 '18 at 08:05

1 Answers1

0

Ok thank you, I was indeed using setlocal enabledelayedexpansion, but I didn't replace the %variable% by !variable! . So now this code is working :

set "downloadurl=!url!%%A"

Thank you !

A.

Antoine
  • 355
  • 2
  • 12