Solved

How to Robocopy  a file to a variable folder name.

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

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

Suggested Solutions

Title # Comments Views Activity
Run MS Access Module from Macro / Bat File 9 87
Creating 2 files from output with Powershell 5 44
What is assert.deepEqual? 4 46
Need some help with powershell script 5 48
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 …
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

813 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

16 Experts available now in Live!

Get 1:1 Help Now