Share via

Batch file question

Anonymous
2022-09-12T13:57:35+00:00

I have a MS Access database which uses SQL Server as a backend. I want multiple people to use the database so for ease of distribution I created batch files the go out to a folder and copy the file to a temp folder. That way they always have the latest version if I make changes to the front end. The master file lives in a shared OneDrive folder. The issue I have is that of my users 1 has his OneDrive on his D drive while others have it on their C drive.

What I would like is for the batch file to see if D:\OneDrive\Eagles_GrandReceiver exists. If it does run the code that was in file 1 and if not run the code that was in file 2.

Is this even possible?

These files both do the same thing in that they copy a master file from one folder to another

File 1:

rem @echo off

cd C:\

if not exist "C:\FEcopy" mkdir "C:\FEcopy"

DEL "C:\FEcopy\GrandReceiver.accdb"

COPY D:\OneDrive\Eagles_GrandReceiver\Distribution\MasterFile\Eagles_GrandReceiver_Master.accdb "C:\FEcopy\GrandReceiver.accdb"

C:\FEcopy\GrandReceiver.accdb"

rem @RD /S /Q "C:\FEcopy"

EXIT /b

File 2:

@echo off

cd C:\

if not exist "C:\FEcopy" mkdir "C:\FEcopy"

DEL "C:\FEcopy\EaglesAgent.accdb"

COPY C:\Users"%USERNAME%"\OneDrive\Eagles\Distribution\MasterFile\EaglesAgent_Master.accdb "C:\FEcopy\EaglesAgent.accdb"

Start /wait C:\FEcopy\EaglesAgent.accdb"

@RD /S /Q "C:\FEcopy"

EXIT /b

Windows for home | Windows 11 | Files, folders, and storage

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

2 answers

Sort by: Most helpful
  1. Anonymous
    2022-09-12T17:46:34+00:00

    Thank you that proved very worthwhile.

    Just in case someone is wondering here is the solution:

    @echo off

    set DRIVE=none

    if exist " C:\Users"%USERNAME%"\OneDrive\Eagles\Distribution " set DRIVE=C

    if exist "D:\OneDrive\Eagles_GrandReceiver" set DRIVE=D

    if %drive% == none echo "Drive not found . . ."

    If %drive% == none pause

    If %drive% == none exit

    Echo Drive found as %DRIVE%

    mkdir C:\FECopy_GrandReceiver

    DEL C:\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

    COPY %DRIVE%:\OneDrive\Eagles_GrandReceiver\Distribution\MasterFile\Eagles_GrandReceiver_Master.accdb "C:\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

    Start /wait C:\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

    DEL C:\FECopy_GrandReceiver\Eagles_GrandReceiver_Copy.accdb"

    EXIT /b

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Les Ferch 10,341 Reputation points Volunteer Moderator
    2022-09-12T14:28:55+00:00

    For help with batch files, I recommend asking your question at tenforums.com or elevenforum.com. There are lots of batch file enthusiasts there that will be happy to help out.

    Was this answer helpful?

    0 comments No comments