Solved

How to Robocopy  a file to a variable folder name.

Posted on 2013-11-18
3
990 Views
Last Modified: 2013-11-26
How to Robocopy  a file to a variable folder name.
I am current trying to manage files in a jboss war file (deploy\tmp543236qcbin-exp.war\) folder that changes its name on every start. It is a cached set of files.
One task:
Manage an image. Want to replace image in cached folder. (deploy\tmp543236qcbin-exp.war\images)
Second task:
Replace an html file in the cache folder.
Did not see any parameters in robocopy to allow us to send file file to a wildcard folder.
0
Comment
Question by:williamfl
3 Comments
 
LVL 30

Expert Comment

by:hnasr
ID: 39659526
You may set a variable for any part of the command and expand as %variable% in the proper place of the command.

Example:
Robocopy.exe  d:\ G:\f\ *.txt

Set sd=D
Set df = G:\f
Set files = *.txt

Robocopy.exe  %sd%:\ %df%\ %files%

Don't forget usual options for purge and exclude ..
0
 
LVL 83

Accepted Solution

by:
oBdA earned 300 total points
ID: 39673809
This should give you the target folder; just set the variable "CacheRoot" to the folder where the tmp folder is created, and CacheFilter to the proper mask (you can use *.* as well if there's only ever a single folder in the root folder).
You can use the variable Cachefolder after line 22 to address the cache folder. Currently, it will only display the folder (or errors) found:
@echo off
setlocal enabledelayedexpansion
set CacheRoot=C:\Temp\deploy
set CacheFilter=tmp*
set /a TargetCount = 0
for /d %%a in (%CacheRoot%\%CacheFilter%) do (
	set /a TargetCount += 1
	set TargetList[!TargetCount!]=%%a
)
if "%TargetCount%"=="0" (
	echo Error: No cache folder matching '%CacheFilter%' found in '%CacheRoot%'.
	pause
	goto :eof
)
if "%TargetCount%" gtr "1" (
	echo Error: More than one cache folder matching '%CacheFilter%' found in '%CacheRoot%':
	for /l %%i in (1, 1, %TargetCount%) do (echo - !TargetList[%%i]!)
	pause
	goto :eof
)
set CacheFolder=%TargetList[1]%
echo Cache folder found: %CacheFolder%

Open in new window

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
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 …
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)
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

743 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

10 Experts available now in Live!

Get 1:1 Help Now