Solved

question about windows batch/script

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unmap server backup drives 6 27
ebay desktop program for windows for a seller who wants to sell alot 2 30
how to export this list 4 41
Remote control Windows CE 7 51
NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
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). …
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 …

810 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