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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:24:49+00:00 2026-06-05T06:24:49+00:00

Lets say i want to copy a file from one location to another with

  • 0

Lets say i want to copy a file from one location to another with this code:

@set FILE=%1
@set SCRDIR=C:\test dir
@set DSTDIR=%SCRDIR%\temp

for %%f in ("%SCRDIR%\%FILE%") do @(
    echo Copying "%%f" to "%DSTDIR%"
    copy "%%f" "%DSTDIR%"
)

The file exists:

 C:\test dir>dir /b copyme.txt
copyme.txt

First i call the script with the name of the file as argument i want to copy:

C:\test dir>test.bat rename.txt

C:\test dir>for %f in ("C:\test dir\rename.txt") do @(
echo Copying "%f" to "C:\test dir\temp"
 copy "%f" "C:\test dir\temp"
)
Copying ""C:\test dir\rename.txt"" to "C:\test dir\temp"
The system cannot find the file specified..

The above copy command fails, because of the extra quotes…

Now i call the script with the file name containing a wildcard * :

C:\test dir>test.bat copyme.*

C:\test dir>for %f in ("C:\test dir\copyme.*") do (
echo Copying "%f" to "C:\test dir\temp"
 copy "%f" "C:\test dir\temp"
)

C:\test dir>(
echo Copying "C:\test dir\copyme.txt" to "C:\test dir\temp"
 copy "C:\test dir\copyme.txt" "C:\test dir\temp"
)
Copying "C:\test dir\copyme.txt" to "C:\test dir\temp"
        1 file(s) copied.

In the above example, where im using a wildcard, it works perfectly fine.

Can anyone explain this behaviour? Why does windows add extra quotes when im not using wildcards? Or is it omitting the extra quotes, because im using wildcards?
I have to quote the path\filename for the FOR loop in order to handle paths, which contain blanks, so omitting those is not an option.

  • 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-05T06:24:51+00:00Added an answer on June 5, 2026 at 6:24 am

    when there are no wildcards, for command doesn’t check if the file exists, so effectively treats its name as a string literal, quotes included.
    Just use "%%~f" instead of "%%f"

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

Sidebar

Related Questions

lets say I have (linux/unix) /directory/1/file.wmv /directory/2/file.wmv /directory/3/file.wmv I want to copy these .wmv
I would appreciate any help on this issue. Lets say I want to load
I need to copy files from one directory to another (pretty obvious :) )
Lets say that this is my .xmi file to be parsed; <?xml version=1.0 encoding=UTF-8?>
How can I copy data from one table (table A) to another (table B)
So lets say I want to make a deep copy of an object, but
Lets say I want to make a class myClass with two slots A and
lets say you want to get all the columns of a table, but exclude
Lets say I want to define 2 styles. .color_red { color: Red; } .banner
Lets say we want a library of javascript-based pieces of functionality (I'm thinking jquery):

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.