Solved

How to Robocopy  a file to a variable folder name.

Posted on 2013-11-18
3
1,027 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

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

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
The viewer will learn how to count occurrences of each item in an array.
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.

910 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

20 Experts available now in Live!

Get 1:1 Help Now