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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:31:04+00:00 2026-06-07T18:31:04+00:00

Basically I have a command which will copy the contents of a source directory

  • 0

Basically I have a command which will copy the contents of a source directory (and sub-directories), and flatten the structure into a target directory, overwriting any duplicates.

This is the raw command that works from the command line

for /r 5.1.0.60 %f in (*) do @copy "%f" "deployment" /y

in this instance where

  • “5.1.0.60” is the output directory of a prior TeamCity / MSBuild task
  • “deployment” is the target directory for the flattened output of the step

However, when I run this command from inside of an MSBuild task (ultimately as part of a TeamCity build), I am getting the following error

f" deployment /y was unexpected at this time

I have the following basic msbuild script that exhibits the issue:

<Project DefaultTargets="flatten"
        xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
        ToolsVersion="3.5">
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />

  <PropertyGroup>
    <SourceDir>5.1.0.60</SourceDir>
    <TargetDir>deployment</TargetDir>
  </PropertyGroup>

  <Target Name="flatten">
    <!-- create our deployment directory -->
    <MakeDir Directories="$(TargetDir)"/>

    <!-- Copy all files flattenend to the deployment directory-->
    <Message Text="##Command  [for /r $(SourceDir) %f in (*) do @copy &quot;%f&quot; $(TargetDir) /y]"/>
    <Exec Command="for /r $(SourceDir) %f in (*) do @copy &quot;%f&quot; $(TargetDir) /y" />

  </Target>    
</Project>

Ultimately, if a past the line

for /r 5.1.0.60 %f in (*) do @copy "%f" "deployment" /y

into a batch file and run the batch file on its own (outside of msbuild) I get the same error, so presumably it’s strictly a cmd issue rather than MSBuild, though since I imagine this is a common task in MSBuild / TeamCity I’ve tagged those as well.

Any help or pointers would be most appreciated.
(NB windows 7 pro, TeamCity 6.5)

  • 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-07T18:31:07+00:00Added an answer on June 7, 2026 at 6:31 pm

    FOR variables use a single percent (%f) when used on the command line, but two percents (%%f) are required when used in in a batch file.

    I’m not sure if TeamCity executes your command in a command line context or from within a temporary batch file.

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

Sidebar

Related Questions

I basically have to write a clone of the UNIX ls command for a
I basically have the following class: .sf-sub-indicator { background: url(/abcprod/images/arrows-ffffff.png) no-repeat -10px -100px; }
I have a small perl script ( found here ) which adds command line
I have a Java class which can be called from shell. (via java [command][options])
I have an application in vb.net which will connect with an hardware device and
I wish to have a small dialog based application which is passed command line
We have a print engine which basically picks pre defined tasks to run against
I have a small project which will use iPad as an information kiosk for
Basically I have got two things i am passing from a command argument <asp:LinkButton
I have a program which will be running continuously writing output to stdout, and

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.