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

  • SEARCH
  • Home
  • 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 8642733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:51:12+00:00 2026-06-12T11:51:12+00:00

I have a groovy script that renames files that match a regex I launch

  • 0

I have a groovy script that renames files that match a regex
I launch it this way

C:\>groovy rename test.* test.txt

It works fine.

But when I try to pass this regex:

C:\>groovy rename test\.(.*) $1_TEST_$1

the command line returns a message:

The syntax of the command is incorrect

and it’s not my script – its cmd that writes this. My script never even runs. It also happens even when I wrap the arguments (regex) in quotes.

Q: Why? How can I pass any regex as param?


Since nobody can figure out what’s going on, I’ve made an even simpler example:

test.groovy

println args[0]

I run it: groovy test Bob and the output is, not suprisingly, Bob.
But when I run e.g. groovy test .* I get The syntax of the command is incorrect. When I run it groovy test * then a name of a pdf file comes out (that happens to be in the same dir as test.groovy)

  • 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-12T11:51:14+00:00Added an answer on June 12, 2026 at 11:51 am

    OK, this appears to be a bug in the startgroovy.bat batch file. The error occurs here:

    rem remove the leading space we'll add the first time
    if "x%_ARG:~0,1%" == "x " set _ARG=%_ARG:~1%
    

    But the problem is a few lines previously:

    rem remove quotes around first arg
    for %%i in (%1) do set _ARG=%_ARG% %%~i
    

    This doesn’t work as intended if the argument contains wildcards. Certain cases (including a single asterisk) are worked around earlier in the script and others sort of work because the wildcard matches successfully; in this case you don’t get an error but the matching file is passed to the Groovy script rather than the wildcard. There are also cases where the wildcard would match but doesn’t because the workaround has mangled it.

    As near as I can figure, the intent is to not process wildcards, so the fix is straightforward:

    rem remove quotes around first arg
    for /F %%i in (%1) do set _ARG=%_ARG% %%~i
    

    Now it works for me:

    H:\>groovy test .*
    .*
    

    I was intending to submit a bug report, but it looks as if I can’t do so without first registering with the project web site, so you can submit one if you like.

    Side note:

    Although the problem is caused by the bug in startgroovy.bat it also exposes a bug (or, at least, an odd behaviour) in the Windows batch processor; environment variable substring expansion behaves oddly if the variable doesn’t exist. The if line shown above works as expected (no environment variable substitution) on the command line, but in a batch file it gets mangled, coming out as:

    if "x~0,1_ARG:~1
    

    Hence the syntax error.

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

Sidebar

Related Questions

Similar to this question I have a small groovy test script that basically uses
I have a Groovy script that recurses through a directory looking for .png files,
I have a groovy/grails application that needs to serve images It works fine on
I have a groovy DSL script like this: entity(attribute1:one, attribute2:two) so far so good.
In my Groovy script I have this code: def username = System.getenv()['USER'] def password
I have a groovy script that needs a library in a jar. How do
I have a simple groovy script that generates xml def builder = new groovy.xml.StreamingMarkupBuilder()
Hey I have created a Groovy script that will extract the version numbers of
I have just tried to write my first ever Groovy script and noticed that
I have seen the at (@) sign in Groovy files and I don't know

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.