Solved

question about windows batch/script

Posted on 2016-10-11
3
40 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
3 Comments
 
LVL 83

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

Why spend so long doing email signature updates?

Do you spend loads of your time carrying out email signature updates? Not very interesting are they? Don’t let signature updates get you down. Let Exclaimer Cloud - Signatures for Office 365 make managing email signatures a breeze.

Join & Write a Comment

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…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

759 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

24 Experts available now in Live!

Get 1:1 Help Now