Solved

question about windows batch/script

Posted on 2016-10-11
3
70 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 84

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

726 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