Solved

Script to copy file to Randomly generated Directory

Posted on 2012-04-05
11
601 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 52

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 52

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
 

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 52

Expert Comment

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

~bp
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

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 52

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 52

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 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
regedit.exe REG ADD problems 2 35
copy-item script help 15 66
Do Psexec queries install files on remote computers 6 44
Questions about this React unit test 4 43
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
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…
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…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

911 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

28 Experts available now in Live!

Get 1:1 Help Now