Solved

Script to copy file to Randomly generated Directory

Posted on 2012-04-05
11
654 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
11 Comments
 
LVL 55

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 55

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
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 

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 55

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 55

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 55

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 55

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

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

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

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

696 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