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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T11:24:03+00:00 2026-06-02T11:24:03+00:00

I have the misfortune of working with a program which requires all filenames passed

  • 0

I have the misfortune of working with a program which requires all filenames passed into it to be valid URLs. (No, I don’t know why.) Rather than having to drop to the command line and hand-craft file: URLs each time, I’m throwing together a batch file onto which I can simply drop files dragged from the Windows GUI.

A full, proper URL encoder is beyond my needs or interest (most of the characters the app chokes on aren’t valid in Windows filenames, anyway), but the two cases I do need to solve are backslashes and spaces. Backslashes are easily handled by variable replacement syntax (SET URL=%URL:\=/%), but spaces are tricky — % is special for both URLs and batch files.

Neither type of batch escaping I’m familiar with (^%, %%) allows the variable replacement to behave as desired and I haven’t had any success Googling a solution. Can any batch gurus help me out?

Here’s what I have so far:

@ECHO OFF

SETLOCAL

SET URLPATH=file:/%~dp1
SET URLPATH=%URLPATH:\=/%

REM none of these work
REM SET URLPATH=%URLPATH: =%20%
REM SET URLPATH=%URLPATH: =%%20%
REM SET URLPATH=%URLPATH: =^%20%

REM works; I just need to figure out how to generate it
SET URLPATH=file:/C:/Documents%%20and%%20Settings/bblank/example.dat

stupidapp.exe %URLPATH%

ENDLOCAL
  • 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-02T11:24:04+00:00Added an answer on June 2, 2026 at 11:24 am

    Side note – I believe you want %~f1 instead of %~dp1

    You need to switch over to delayed expansion.

    @echo off
    setlocal enableDelayedExpansion
    
    set "URLPATH=file:/%~f1"
    set "URLPATH=!URLPATH:\=/!"
    set "URLPATH=!URLPATH: =%%20!"
    stupidapp.exe !URLPATH!
    
    endlocal
    

    A bit more work is required if any of your file names happen to contain the ! character because it will be corrupted when %1 is expanded if delayed expansion is enabled.

    @echo off
    setlocal disableDelayedExpansion
    set "URLPATH=file:/%~f1"
    setlocal enableDelayedExpansion
    set "URLPATH=!URLPATH:\=/!"
    set "URLPATH=!URLPATH: =%%20!"
    stupidapp.exe !URLPATH!
    
    endlocal
    endlocal
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have a rather abstract question for you all. I'm looking at getting involved in
So i have the misfortune of embedding this proprietary ActiveX control we created into
Have you ever tried working with a XAML file which contains thousand tons of
I have the misfortune of having use conio.h in vc++ 6 for a college
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
Have an EXE which implicitly loads some DLL's and others explicitly (LoadLibrary). This EXE
Have finally got a responsive site working (of a fashion). What I want to
Have posting working wonderfully, and reading the response happily EXCEPT when one of the

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.