[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

question about windows batch/script

Posted on 2016-10-11
3
Medium Priority
?
96 Views
Last Modified: 2016-10-11
Using multi systems with windows 10, windows 7 32 and 64 bit

I want in a batch file something like this

set ddir=
if exist "c:\123 456" set ddir="c:\123 456"
if exist "c:\456 dsds" set ddir="c:\456 dsds"
if exist "c:\otherdir" set ddir="otherdir"

xcopy /s /e %ddir%\*.* d:\backup

Wat is the best way to go

Thanks Danny
0
Comment
Question by:Danny Kon
[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 85

Accepted Solution

by:
oBdA earned 2000 total points
ID: 41838009
Do you really only want to copy only one of the folders in the list, or do you want to copy any folder that is in the list and found?
This script will copy just one existing folder from the list (if multiple folders were found, the last one will be used).
It's in test mode and will only show the robocopy command it would normally run. Remove the uppercase ECHO in line 14 to run it for real.
@echo off
setlocal enabledelayedexpansion
set SourceList="c:\123 456" "c:\456 dsds" "c:\otherdir"
set Target=D:\Backup
set Source=
for %%a in (%SourceList%) do (
	if exist "%%a" set Source=%%a
)
if not defined Source (
	echo No supported source folder found.
	exit /b 1
)
echo Source folder found: '%Source%'
ECHO robocopy.exe "%Source%" "%Target%" /e /r:0

Open in new window

0
 
LVL 6

Author Comment

by:Danny Kon
ID: 41838026
oBdA

Thanks for your quick response, i put a new question because this will not always solve the problem

Thanks Danny
0
 

Expert Comment

by:John Sam George
ID: 41838027
Use Powershell.

if((Test-Path c:\123 456) -eq "True")
$ddir="c:\123 456"

Copy-Item c:\123 456 d:\backup -recurse
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

This is a fine trick which I've found useful many times, when you just don't want to accidentally run a batch script or the commands needs administrator rights.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

649 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