Solved

Script to copy file to Randomly generated Directory

Posted on 2012-04-05
11
641 Views
Last Modified: 2012-04-06
I am trying to create a script to copy a file from one directory to another directory that is randomly named by Firefox. The folder is a profile directory and it's different for every installation. As you can see below the random characters are just before the '.default' string. I tried using a wild card but it didn't work.

%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default\

This is what I attempted without any luck:

xcopy \\domain\netlogon\file.txt  %USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default

Any help would be appreciated.
0
Comment
Question by:swhitti
  • 6
  • 5
11 Comments
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 37814715
Here's a BAT file that should do the job:
@echo off
for /D %%A in ("%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default") do xcopy "\\domain\netlogon\file.txt" "%%~A"

Open in new window

~bp
0
 

Author Comment

by:swhitti
ID: 37816527
That was perfect! Thanks so much for the help. I will be giving you the full points.

It turns out that I also have to append a line,

user_pref("extensions.blocklist.url", "127.0.0.1");

to a specific file called pref.js in that same random generated directory.

If adding this to a current request is not acceptable please let me know and I will be happy to open another question.

Thanks again!
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 37816655
Give this a try, I think it should do what you described.
@echo off
for /D %%A in ("%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default") do (
  xcopy "\\domain\netlogon\file.txt" "%%~A"
  echo user_pref("extensions.blocklist.url", "127.0.0.1"); >>"%%~A\pref.js"
)

Open in new window

~bp
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Author Comment

by:swhitti
ID: 37816712
Thanks for continuing to help me.

It copied the line I needed but included some additional info also, this is what was appended:

\\domain\netlogon\file.txt
1 File(s) copied
user_pref("extensions.blocklist.url", "127.0.0.1"
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 37817339
Can you post up the script you ran please.

~bp
0
 

Author Comment

by:swhitti
ID: 37817519
It is basically the same script you supplied me with a few changes to the domain and file name.

@echo off
for /D %%A in ("%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default") do (
  xcopy "\\domain\netlogon\blocklist.xml" "%%~A"
  echo user_pref("extensions.blocklist.url", "127.0.0.1"); >>"%%~A\prefs.js"
)

In the pref.js file it appends this to the bottom of the file:

\\domain\netlogon\file.txt
1 File(s) copied
user_pref("extensions.blocklist.url", "127.0.0.1"

I don't need the line about the file path or the '1 File(s) copied' and it is missing the closed bracket and semicolon, ie. );

or

user_pref("extensions.blocklist.url", "127.0.0.1");
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 37817527
Interesting, let me play with that, I suspect it's the parenthesis after the 127.0.0.1 that is an issue, we should be able to work around that.

~bp
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 37817565
Okay, try this, it should work.
@echo off
for /D %%A in ("%USERPROFILE%\AppData\Roaming\Mozilla\Firefox\Profiles\*.default") do (
  xcopy "\\domain\netlogon\blocklist.xml" "%%~A"
  echo user_pref^("extensions.blocklist.url", "127.0.0.1"^); >>"%%~A\prefs.js"
)

Open in new window

~bp
0
 

Author Comment

by:swhitti
ID: 37817588
You're AMAZING! I can't thank you enough for working on this for me. That worked perfectly. If there is any way of giving you more points let me know and I would be happy to do so. :)

Have a great weekend...
0
 

Author Comment

by:swhitti
ID: 37817667
I have one more requirement which I will open a new question for as I want you to be able to answer and get points for, if you feel inclined. Please keep an eye out for it.
0
 
LVL 54

Expert Comment

by:Bill Prew
ID: 37817915
Sorry, was away from the computer for a while so missed that until just now, but glad you got some help with it.

~bp
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

749 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