Copy a file to a folder specified by a wildcard

Posted on 2009-04-22
Last Modified: 2012-05-06
I want to copy a file (prefs.js) from C: to a randomly named folder called 'something.default', I feel the following should work:

xcopy c:\prefs.js "C:\Documents and Settings\SETUP\Application Data\Mozilla\Firefox\Profiles\*.default" /q /v

What hapens is a file called 'Prefs.default' appears in C:\Documents and Settings\SETUP\Application Data\Mozilla\Firefox\Profiles

Why is this, how can I get the script to copy the file I want?
Question by:Pete
    LVL 28

    Expert Comment

    *.default will be always interpreted as a file, not as a folder and the * will take the name left of the . from the original file and apply it to the target, therefor ethe rename.

    A real "random" function is not availaible in bacths cripts. You may have succes with %RANDOM%.
    SO give this batch a try:

    md  "C:\Documents and Settings\SETUP\Application Data\Mozilla\Firefox\Profiles\%TARGET%"
    xcopy c:\prefs.js "C:\Documents and Settings\SETUP\Application Data\Mozilla\Firefox\Profiles\%TARGET%" /q /v

    LVL 1

    Author Comment

    Thanks your script creates a folder called PRF*something* and then copies prefs.js to it. I need to copy prefs.js to an exisiting folder called (for example) sdf566.default.
    Thanks, making progress
    LVL 28

    Accepted Solution

    Ah, sorry, I've misunderstood your orginal question. If there is only one folder with .default, this should do it:

    For /d %%A in ("C:\Documents and Settings\SETUP\Application Data\Mozilla\Firefox\Profiles\*.default") Do xcopy c:\prefs.js "%%A" /q /v

    LVL 1

    Author Closing Comment

    Thanks this works great

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Join & Write a Comment

    This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now