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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:17:14+00:00 2026-06-06T15:17:14+00:00

When creating a Post-Build event in VS2008, I want to check if the target

  • 0

When creating a Post-Build event in VS2008, I want to check if the target for an xcopy operation is not readonly. I found some code ( http://forums.techguy.org/dos-other/842311-solved-checking-if-file-folder.html ) that makes use of a temporary variable and later checks that for certain attribs.
It does not work.
When I manually print the variable, it seems to be empty.

if $(PlatformName)==x86 (
  echo x86
  For /F "Delims=" %%I In ('Attrib $(ProjectDir)..\..\somedir\$(ConfigurationName)    \somemoredir\$(TargetName).dll') Do Set _Attribs=%%I
  If NOT "%_Attribs:~5,1%"=="R" (
    set test="monkey"
    echo %test%
    echo $(test)
    echo nono
    echo %_Attribs%
    echo $(ProjectDir)..\..\somedir\$(ConfigurationName)\somemoredir\$(TargetName).dll
    attrib $(ProjectDir)..\..\somedir\$(ConfigurationName)\somemoredir\$(TargetName).dll
    xcopy /Y $(ProjectDir)..\..\..\Runtime\bin\$(TargetName).*     $(ProjectDir)..\..\somedir\$(ConfigurationName)\somemoredir\
  )

)

output is:

x86
ECHO is on.
ECHO is on.
nono
ECHO is on.

then the attrib message and so on.

echo %test%, echo $(test) and so on seem to show that the test variable does not contain anything.

How can I use environment variables?

(BTW, _Attribs, which I am really interested
in, also does not contain anything.)

  • 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-06T15:17:17+00:00Added an answer on June 6, 2026 at 3:17 pm

    You have a classic problem for batch newbies – You can’t look at a value you just set within a loop (parentheses) because the entire loop is parsed at once. So you are seeing the value of your variable before the loop was executed – obviously not going to work. The solution is to enable delayed expansion with SETLOCAL EnableDelayedExpansion and then expand your variable using delayed expansion as !var!.

    Your other issue of how to get the file attributes – you can use the ~a FOR variable expansion modifier to get the list of attributes. In typical Microsoft fashion, the attributes are not listed in the same order or case as the ATTRIBUTES command. The read only flag is r in the 2nd character (position 1).

    Both delayed expansion and modifiers are explained in the documentation: Simply type HELP FOR or FOR /? from a Windows command line. Simply run CMD from the Start menu to get a command line.

    setlocal enableDelayedExpansion
    if $(PlatformName)==x86 (
      echo x86
      for %%F In ("Attrib $(ProjectDir)..\..\somedir\$(ConfigurationName)\somemoredir\$(TargetName).dll") do set _Attribs=%%~aF
      if not "!_Attribs:~1,1!"=="r" (
        set test="monkey"
        echo !test!
        echo $(test)
        echo nono
        echo !_Attribs!
        echo $(ProjectDir)..\..\somedir\$(ConfigurationName)\somemoredir\$(TargetName).dll
        attrib $(ProjectDir)..\..\somedir\$(ConfigurationName)\somemoredir\$(TargetName).dll
        xcopy /Y $(ProjectDir)..\..\..\Runtime\bin\$(TargetName).*  $(ProjectDir)..\..\somedir\$(ConfigurationName)\somemoredir\
      )
    )
    

    You could use the ATTRIB command as in your original command – just make sure to use !_Attribs:~5,1! instead of %_Attribs:~5,1%. But the ~a modifier solution I provided is more efficient since it uses a simple FOR loop and doesn’t have to execute a command using FOR /F.

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

Sidebar

Related Questions

I am creating a nuget package and I want it to add a post-build
I'm creating a plugin for wordpress and I need to check if a post
I'm creating some restful apis. There is a register api, user can POST an
I am creating an UITableView, every thing goes fine in code and build got
I've been reading this post Creating a login form in CodeIgniter based on Ion
I am creating a page where people can post articles. When the user posts
I am creating a regex library to work with HTML (I'll post it on
I am creating an online blog website and for each blog post, I'd like
What are the strengths of GET over POST and vice versa when creating an
I have a small application where I am creating a customer [Authorize] [AcceptVerbs(HttpVerbs.Post)] public

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.