Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to Robocopy  a file to a variable folder name.

Posted on 2013-11-18
3
Medium Priority
?
1,312 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 31

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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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…
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 …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…
Suggested Courses

618 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