?
Solved

How to Robocopy  a file to a variable folder name.

Posted on 2013-11-18
3
Medium Priority
?
1,245 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
[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
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 85

Accepted Solution

by:
oBdA earned 1200 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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 …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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…
Suggested Courses

770 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