Solved

Script to copy file to Randomly generated Directory

Posted on 2012-04-05
11
610 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 53

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 53

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 53

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 53

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 53

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 53

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

832 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