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 4076626
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:26:57+00:00 2026-05-20T17:26:57+00:00

Referring to What is the best way to do a substring in a batch

  • 0

Referring to What is the best way to do a substring in a batch file? I think the below should work.

FOR %%f IN (*.wav) DO CALL :runthis "%%f"
rem del temp.wav tmpfile
GOTO :EOF

:runthis
set "outdir=%~p1\output\"
copy "%~1" "%outdir%%~1"

The last command is supposed to dosomthing to all .wav files in current directory and output to existing sub-directory “output” keeping the original filename. Any idea where I’m going wrong?

Update1: Thanks, fixed the syntax. I didn’t notice that %pI expands I to path only, didn’t read carefully. Now what’s wrong is that it’s expanded with the “s

dosomething "11.wav" "\Users\t4\Desktop\Airlines\WavRepeaters\\outdir\"11.wav""

It should be something like::

dosomething "11.wav" c:\Users\t4\Desktop\Airlines\WavRepeaters\outdir\11.wav

Update2: %~dp1 – expands %1 to a drive letter and path only, without the quotations!

  • 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-05-20T17:26:57+00:00Added an answer on May 20, 2026 at 5:26 pm

    The main problem seems to be the use of the parameters.

    In :runthis you use the %~pI, but there isn’t any %I.
    Another pitfall are spaces in the filenames, then dosomething need quotes around the filename / path.

    With some changes it should work

    @echo off
    FOR %%f IN (*.bat) DO CALL :runthis "%%~f"
    rem del temp.wav tmpfile
    GOTO :EOF
    
    :runthis
    set "outdir=%~p1\output\"
    echo dosomthing "%~1" "%outdir%%~1"
    goto :eof
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder what is the best way to use substring function on a string
What is the best way to call a function inside a Linux daemon at
What is the best way to upload a file to a Document Library on
Referring to the Configuration Manager under the Build menu, Is there a way to
Referring to What is the correct way to make a custom .NET Exception serializable?
Given a URL. What is the best way to get the contents of the
i try to find the best way to fetch a blob: I found javassit
Is there any way to declare these classes in a header file without indirection?
I'm trying to figure out the best way to set up my tables/model associations.
I'm not sure the best way to describe what it is that I'm trying

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.