Batch file problem with server name

Eljefegeneo

Still trying to learn
Local time
Today, 05:26
Joined
Jan 10, 2011
Messages
902
I have been trying to set up a batch file to allow users to copy the latest version of the front end whenever a change is made. The following is the code that I am trying to get to work properly. The first part works fine, the old front end is copied to a folder on the user's desktop as a backup. But I cannot get the copy of the server – the "P" drive, to overwrite the current copy on the user's desktop. Actually I cannot get the code to copy the new front end from the server and install it on the user's desktop. I think the path is correct for I seem to be able to run the new front end from the server.


When I look for the location on my computer, the server locations is listed as:
General (\\Servername\files) (P: ) (there is no space after the P: it seems to result in a smiley face when I type it and try to post it).


for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set TODAY=%year%-%month%-%day%
rem echo %TODAY%
for /f "tokens=1 delims=: " %%h in ('time /T') do set hour=%%h
for /f "tokens=2 delims=: " %%m in ('time /T') do set minutes=%%m
for /f "tokens=3 delims=: " %%a in ('time /T') do set ampm=%%a
set NOW=%hour%-%minutes%-%ampm%
rem echo %NOW%

rem copy the old front end to a folder on user's desktop named BackupDB

echo f | xcopy C:\Users\UserName\Desktop\DBMain.accdb C:\Users\UserName\Desktop\OldFE\%TODAY%-%NOW%_dbmain.accdb /f /i

rem copy the new front end to the user's desktop, overwrite the current front end

echo f | xcopy /f/y/ P:\AccessMainSplitBE\NewFrontEnd\DBMain.accdb c:\Users\UserName\Desktop\DBMain.accdb
rem start the new DB front end
Start c:\Users\UserName\Desktop\DBMain.accdb


This code works so I thought that the path was correct
rem this works
rem start the new DB front end
Start P:\AccessMainSplitBE\NewFrontEnd\DBMain.accdb


But this code does not.
echo f | xcopy /f/y/ P:\AccessMainSplitBE\NewFrontEnd\DBMain.accdb c:\Users\UserName\Desktop\DBMain.accdb

Neither does this:

echo f | xcopy /f/y/ \\ServerName\files\P:\AccessMainSplitBE\NewFrontEnd\DBMain.accdb c:\Users\UserName\Desktop\DBMain.accdb

Any help on this would be greatly appreciated.
 
Well, I seem to have solved it myself. After reading many posts on how to copy files from a server, I tried the above code in various versions. After a few days of trying different versions of the above I gave up and posted it on the forum. When I didn't get any replies - I tried it again using a very simplified version. It turns out that since it is a local server, I don't need all the fancy back and forward slashes.
Simpler is better.

The following will copy the old front end to a backup folder on the user's desktop, then copy the new front end to the user's desktop, overwriting the old front end and then start the new front end. I can then update the front end remotely, post it to the "P" drive and send the users to use the batch code that I placed on their desktop.

rem Copy the new
rem start the new DB front end
rem Formulate the day and time to add to the DB name.

for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set year=%%c
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set month=%%a
for /f "tokens=2-4 delims=/ " %%a in ('date /T') do set day=%%b
set TODAY=%year%-%month%-%day%
rem echo %TODAY%
for /f "tokens=1 delims=: " %%h in ('time /T') do set hour=%%h
for /f "tokens=2 delims=: " %%m in ('time /T') do set minutes=%%m
for /f "tokens=3 delims=: " %%a in ('time /T') do set ampm=%%a
set NOW=%hour%-%minutes%-%ampm%
rem echo %NOW%

rem copy the old front end to a folder on user's desktop named BackupDB

echo f | xcopy C:\Users\UserName\Desktop\DBMain.accdb C:\Users\UserName\Desktop\BackupDB\%TODAY%-%NOW%_DBmain.accdb /f /i

rem copy the new front end to the user's desktop
rem start the new DB front end
echo f | xcopy /y P:\AccessMainSplitBE\NewFrontEnd\DBMain.accdb C:\Users\UserName\Desktop\DBmain.accdb
Start C:\Users\UserName\Desktop\folder1\DBmain.accdb
 
Thanks for posting back with your solution. Appreciated.
 

Users who are viewing this thread

Back
Top Bottom