Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8072899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:10:19+00:00 2026-06-05T14:10:19+00:00

I don’t know what the problem is with this batch file: @ECHO OFF SET

  • 0

I don’t know what the problem is with this batch file:

@ECHO OFF
SET images=./images/
SET cdr=%CD%
SET result=noval

CD %images%
SET images=
:: Density
SET dpi=300

:: Process SVG
FOR %%x IN (%images%*.svg) DO (
  CALL:testFun %%~nx result
  echo res "%result%"
  IF [%result%]==[process] (
    ECHO Converting %%x
    inkscape -d %dpi% -A %images%%%~nx.pdf %images%%%x
  ) ELSE ( ECHO - Skiping %%x, file is uptodate.)
)

:: Process BMP, JPG, PNG, and TIFF
FOR %%x IN (%images%*.jpg,%images%*.bmp,%images%*.png,%images%*.tiff) DO (
  CALL:testFun %%~nx result
  echo res "%result%"
  IF [%result%]==[process] (
    ECHO Converting %%x
    inkscape -d %dpi% -A %images%%%~nx.pdf %images%%%x 
  ) ELSE ( ECHO - Skiping %%x, file is uptodate.)
)



:: Process EPS
FOR %%x IN (%images%*.eps) DO (
  CALL :testFun %%~nx result
  echo res "%result%"
  IF [%result%]==[process] (
    ECHO Converting %%x
    epstopdf --outfile=%images%%%~nx.pdf %images%%%x
  ) ELSE ( ECHO - Skiping %%x, file is uptodate.)
)

CD %cdr%
ECHO.&PAUSE&GOTO:EOF

::Functions

:testFun
SET "file=%1"
FOR /F %%f IN ('dir /Od /B "%file%.*"') DO (SET newest=%%~xf)
echo * Newest file for %file%: %newest%
IF [%newest%]==[.pdf] (echo noprocessing
GOTO :noprocess) ELSE (echo processing
GOTO :process)
:noprocess
SET result=noprocess
GOTO :endfun
:process
SET result=process
:endfun
GOTO:EOF

The idea is that it should process different images in a directory, only if the images (source) are newer than the resultant PDF (output).

However, there are several problems that I don’t know why they are happening.

  • First, the first loop uses the value of result and print noval all the time, and it looks like it is skipping the function call. But then, the same way of calling works on the second and third loop.

  • Second, in the other loops (in which the first problem doesn’t occur) the value of result, that is changed inside the function, is not there. Like the scope is different. However, I’m using it as a global variable, right? I test this version using set local and passing the variable as reference but nothing work.

What I’m doing wrong or missing here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:10:21+00:00Added an answer on June 5, 2026 at 2:10 pm

    The code runs as it should. What you are not aware of is that cmd expands environment variables when parsing a command. A command in this case can be a complete for including the block. So after parsing it no variables remain in it, only text. Which means if you change a variable within a block and use it in the same block you won’t see the change.

    To resolve this you can use delayed expansion which ensures that variables are expanded directly prior to running a single line (even within blocks) and thus mitigate this problem. Add the following at the top of your batch file:

    setlocal enabledelayedexpansion
    

    and then use !result! instead of %result% to access the variables’ values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if this is an eclipse specific problem but whenever I declare a
Don't know why this doesn't work. I can't do implicit animation for a newly
I don't know how --retry-max-time calculated. If I download a file file.txt : curl
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know if this has been asked before, so point me to another question
Don't know if anyone can help me with this or if it's even possible.
I don't know: if this works. if it's a good idea. what it is
I don't know if this question is trivial or not. But after a couple
Don't know if this is the right place to ask this, but I will
Don't know why this is happening, but after submitting a form via JS (using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.