Solved

BAT file to automate copying files from vpn network to local machine.

Posted on 2008-10-10
7
1,317 Views
Last Modified: 2010-08-05
Hi, I'm trying to make a BAT file that will automate file management tasks on Windows XP. I would like to do the following:

1)      Check to see if a path exists
   a.      If fail, quit and throw a message box Did not connect
   b.      If success, continue
2)      Copy files from the network resource to the local machine
3)      Test to see if the files were successfully written to local machine
   a.      If fail, message box failed, try again
   b.      If success, message box Copy successful

I guess it will look something like this but I'm sure you'll recognize my VBAish looking if statements:

If { o:\data\files\copyme.mdb path exists } Then
   REM Copy file from O: to C:
   copy /Y o:\data\files\copyme.mdb c:\localdata\copyme.mdb
   copy /Y o:\data\files\copymeToo.mdb c:\localdata\copymeToo.mdb
Else
   Message Box O: Drive not connected
   Exit
End If

If {copy successful} Then
   Message Box Success
Else
   Message Box Copy failed, try again
End if

Exit

I'm a beginner so if I'm going about this the wrong way please let me know. Thanks.
0
Comment
Question by:BradleyOnTheRoad
[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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 23

Expert Comment

by:Danny Child
ID: 22689062
Here's how to check the path:
http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_23317031.html

and you can get info to the screen with the ECHO command.
0
 

Author Comment

by:BradleyOnTheRoad
ID: 22689667
OK, I took that example and changed it to

@echo off
setlocal
set dr_=C:\FolderDoesNotExist
 
if not exist "%dr_%" (echo Folder "%dr_%" not found goto :EOF)

The BAT file flashes the cmd screen for a second and then goes away. Why isn't there a message to tell me the folder doesn't exist?
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22690374
There's no pause. Opening from a command prompt will echo.

Try this.

@echo off
setlocal 
set dr_=C:\FolderDoesNotExist
 
if not exist "%dr_%" (echo Folder "%dr_%" not found & pause & goto :EOF)

Open in new window

0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 21

Expert Comment

by:AmazingTech
ID: 22690524
You'll need to find some thing the popup the message box.

NET SEND may work for you.
If exist "o:\data\files\copyme.mdb" (
   REM Copy file from O: to C:
   copy /Y o:\data\files\copyme.mdb c:\localdata\copyme.mdb
   If NOT ERRORLEVEL 1 (
       Message Box Successfully copied copyme.mdb
   ) Else (
       Message Box Failed copying copyme.mdb, try again
   )
 
   copy /Y o:\data\files\copymeToo.mdb c:\localdata\copymeToo.mdb
   If NOT ERRORLEVEL 1 (
       Message Box Successfully copied copymeToo.mdb
   ) Else (
       Message Box Failed copying copymeToo.mdb, try again
   )
 
) Else (
   Message Box O: Drive not connected
   GOTO :EOF
)

Open in new window

0
 
LVL 1

Expert Comment

by:robertodf
ID: 22690674
Try this:
Let me know if you have any questions

save the following as soluition.cmd

:: Author: Robertodf
:: Batch file to copy files from network share or network drive to local folder
:: Filename: solution.cmd
::
:: 1. Check for network folder availability
if not exist \\server\share\file_or_directory goto notexist

:: 2. Copy folder contens to local machine
xcopy \\server\share\folder\*.* c:\localdir /s

:: 3. Test for local folder contents
if not exist c:\localdir\filename.tst goto errorlocal
echo Copy was successful
goto end

:notexist
echo File or Folder not exist
goto end

:errorlocal
echo Local File or Folder not exist, try again
goto end

:end
0
 
LVL 1

Accepted Solution

by:
robertodf earned 500 total points
ID: 22690721
Well if the batch flashes with out indicating success or failure we can change it like this (you will have to press a key after the message to continue)::

:: Author: Robertodf
:: Batch file to copy files from network share or network drive to local folder
:: Filename: solution.cmd
::
:: 1. Check for network folder availability
if not exist \\server\share\file_or_directory goto notexist

:: 2. Copy folder contens to local machine
xcopy \\server\share\folder\*.* c:\localdir /s

:: 3. Test for local folder contents
if not exist c:\localdir\filename.tst goto errorlocal
echo Copy was successful
pause>nul

goto end

:notexist
echo File or Folder not exist
pause>nul
goto end

:errorlocal
echo Local File or Folder not exist, try again
pause>nul
goto end

:end
0
 

Author Closing Comment

by:BradleyOnTheRoad
ID: 31505112
Thanks, I see how the conditional statements - as well as the pause - works now.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Map drive keeps removing itself 9 95
how to pick only current date files from a ftp 14 65
Windows XP under Hyper-V Server 2016 15 326
Odd Coloration 4 44
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

734 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