Solved

question about windows batch/script

Posted on 2016-10-11
3
79 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 500 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

707 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