Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Copy a file to a folder specified by a wildcard

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?
Ta
0
Pete
Asked:
Pete
  • 2
  • 2
1 Solution
 
Michael PfisterCommented:
*.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:

Set TARGET=PRF%RANDOM%
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

0
 
PeteAuthor Commented:
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
0
 
Michael PfisterCommented:
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

0
 
PeteAuthor Commented:
Thanks this works great
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now