Batch file - Unable to get databases to copy to correct file location

Unable to get databases to copy to correct file location

Page 1 of 1

11 Replies - 1396 Views - Last Post: 10 November 2008 - 07:42 AM Rate Topic: *---- 1 Votes

#1 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Batch file - Unable to get databases to copy to correct file location

Posted 05 November 2008 - 07:02 AM

I need the code below to copy the database to the following location C:\Program Files\jkupdate\data\db\tm. If more info is needed please let me know.


:COPYDIR
:: If this dir contains DBs, copy the files to the JK Update Data folder.
:: Else copy all files in this dir to the hard disk.
echo ====== Directory %4
set DOCROOT=%3

if '%4'=='"%CDDBDIR%"' goto :COPYDB1
if '%4'=='"_install"' goto :EOF
xcopy %CDDRIVE%\%4\* %3 /r /e %DATEFLAG% /f /i /s /h /y
cd %~P0
goto :EOF

:COPYDB1
for /D %%D in (%DATAROOT%\*) do %~F0 _copydb2 "%%D"
cd %~P0
goto :EOF

:COPYDB2
for /F %%F in (%2\*) do %~F0 _copydb3 "%%F" %%~nxF
cd %~P0
goto :EOF

:COPYDB3
if exist %CDDRIVE%\%CDDBDIR%\%3 xcopy %CDDRIVE%\%CDDBDIR%\%3 %2 /r /e %DATEFLAG% /f /i /s /h /y
cd %~P0
goto :EOF


Is This A Good Question/Topic? 0
  • +

Replies To: Batch file - Unable to get databases to copy to correct file location

#2 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Batch file - Unable to get databases to copy to correct file location

Post icon  Posted 05 November 2008 - 07:14 AM

I am unable to get databases to copy to the following file location C:\Program Files\jkupdate\data\db\tm. They are currently being copied to the wrong location. I know it is a quick fix, but I just can't figure it out. I have been researching this for a couple of days now.

@echo off

set CDDRIVE=%~D0
set ROOTFILE=%CDDRIVE%\_root.txt
set CDDBDIR=_db
set DATADIR="\Program Files\jkupdate\data\db\tm"


:: Check for command extensions before we start.
if cmdextversion 1 (echo.) else goto :NOCMDEXT

if '%1'=='' goto START
if '%1'=='/d' goto STARTDATE
if '%1'=='_copydir' goto COPYDIR
if '%1'=='_copydb2' goto COPYDB2
if '%1'=='_copydb3' goto COPYDB3

:: Print usage message and bail out.
echo Usage: %0 [/d]
goto :EOF


:STARTDATE
set DATEFLAG=/d

:START
:: Check for existence of the root file.
if not exist %ROOTFILE% goto :NOROOTFILE

:: Get the root folder name from the root file.
cd %CDDRIVE%\
for /F "delims=:" %%f in ('type %ROOTFILE%') do set ROOTDIR=%%f

:: Determine the destination directory for the data.
title Install JTDI Updates
echo Ready to begin install of JTDI updates.
pause
if '%CDDRIVE%'=='F:' goto SKIPF1
set HDDRIVE=f:
set DOCROOT=f:%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:: 2007-02-06:sc: JTDI 1.0 sites will be <drive>:\JTDI\<service>.  Adding check so that this install will work with both structures.
set DOCROOT=f:\JTDI%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:SKIPF1
if '%CDDRIVE%'=='E:' goto SKIPE1
set HDDRIVE=e:
set DOCROOT=e:%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:: 2007-02-06:sc: JTDI 1.0 sites will be <drive>:\JTDI\<service>.  Adding check so that this install will work with both structures.
set DOCROOT=e:\JTDI%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:SKIPE1
if '%CDDRIVE%'=='D:' goto SKIPD1
set HDDRIVE=d:
set DOCROOT=d:%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:: 2007-02-06:sc: JTDI 1.0 sites will be <drive>:\JTDI\<service>.  Adding check so that this install will work with both structures.
set DOCROOT=d:\JTDI%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:SKIPD1
if '%CDDRIVE%'=='C:' goto SKIPC1
set HDDRIVE=c:
set DOCROOT=c:%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:: 2007-02-06:sc: JTDI 1.0 sites will be <drive>:\JTDI\<service>.  Adding check so that this install will work with both structures.
set DOCROOT=c:\JTDI%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:SKIPC1
echo Could not find %ROOTDIR% nor \JTDI%ROOTDIR% directories on hard disk. Exiting.
pause
goto :EOF


:SETDATAROOT
if '%CDDRIVE%'=='F:' goto SKIPF2
set DATAROOT=f:%DATADIR%
if exist %DATAROOT% goto GENLIST

:SKIPF2
if '%CDDRIVE%'=='E:' goto SKIPE2
set DATAROOT=e:%DATADIR%
if exist %DATAROOT% goto GENLIST

:SKIPE2
if '%CDDRIVE%'=='D:' goto SKIPD2
set DATAROOT=d:%DATADIR%
if exist %DATAROOT% goto GENLIST

:SKIPD2
if '%CDDRIVE%'=='C:' goto SKIPC2
set DATAROOT=c:%DATADIR%
if exist %DATAROOT% goto GENLIST

:SKIPC2
set DATAROOT=''

:GENLIST
:: Generate a list of top-level dirs and reinvoke the program once for each dir.
cd %CDDRIVE%\
for /D %%D in (*) do %~F0 _copydir %HDDRIVE% %DOCROOT% "%%D" %DATAROOT%
cd %~P0
goto :EOF

:COPYDIR
:: If this dir contains DBs, copy the files to the JK Update Data folder.
:: Else copy all files in this dir to the hard disk.
echo ====== Directory %4
set DOCROOT=%3

if '%4'=='"%CDDBDIR%"' goto :COPYDB1
if '%4'=='"_install"' goto :EOF
xcopy %CDDRIVE%\%4\* %3 /r /e %DATEFLAG% /f /i /s /h /y
cd %~P0
goto :EOF

:COPYDB1
for /D %%D in (%DATAROOT%\*) do %~F0 _copydb2 "%%D"
cd %~P0
goto :EOF

:COPYDB2
for /F %%F in (%2\*) do %~F0 _copydb3 "%%F" %%~nxF
cd %~P0
goto :EOF

:COPYDB3
if exist %CDDRIVE%\%CDDBDIR%\%3 xcopy %CDDRIVE%\%CDDBDIR%\%3 %2 /r /e %DATEFLAG% /f /i /s /h /y
cd %~P0
goto :EOF



:NOCMDEXT
echo.
echo Command extensions not enabled. Exiting.
pause
goto :EOF

:NOROOTFILE
echo Root file "%ROOTFILE%" not found. Exiting.
pause
goto :EOF


MOD EDIT: Please :code:
Thanks, gabehabe :)

This post has been edited by gabehabe: 05 November 2008 - 08:54 AM

Was This Post Helpful? 0
  • +
  • -

#3 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1385
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Batch file - Unable to get databases to copy to correct file location

Posted 05 November 2008 - 08:38 AM

Moved to Other Languages. :)

Also, please :code:

Haha, it spells fishy:
/f /i /s /h /y

Anyway, what's your database like? Is it a single file? A collection of files? Does it span across just one directory, or does it go into subdirectories, too?
Was This Post Helpful? 0
  • +
  • -

#4 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1385
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Batch file - Unable to get databases to copy to correct file location

Posted 05 November 2008 - 08:54 AM

Please just post your question once. If you post in the wrong forum, a moderator will move it.

Threads merged.
Was This Post Helpful? 0
  • +
  • -

#5 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Batch file - Unable to get databases to copy to correct file location

Posted 05 November 2008 - 08:58 AM

View Postgabehabe, on 5 Nov, 2008 - 07:38 AM, said:

Moved to Other Languages. :)

Also, please :code:

Haha, it spells fishy:
/f /i /s /h /y

Anyway, what's your database like? Is it a single file? A collection of files? Does it span across just one directory, or does it go into subdirectories, too?



They are individual fies. Usually 1-2 databases. They should pull from a CD in a subdirectory. I posted twice. My second post includes the whole code.


View Postgabehabe, on 5 Nov, 2008 - 07:54 AM, said:

Please just post your question once. If you post in the wrong forum, a moderator will move it.

Threads merged.


Sorry. I didn't think the first post went through.
Was This Post Helpful? 0
  • +
  • -

#6 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1385
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Batch file - Unable to get databases to copy to correct file location

Posted 05 November 2008 - 09:49 AM

Without looking over all your code, if it's all grouped together on a disc, why not just use XCOPY to copy it all to a backup dir?

Let me know if this isn't what you're looking for, like I said, I have't read over all your code:

REM Figure out which drive is the disc drive, I'll use E in my example
SET CDDRIVE=E:

XCOPY /e /v /y %CDDRIVE% "C:\Program Files\jkupdate\data\db\tm"


That will copy everything from your disc drive (drive E in my example) to C:\Program Files\jkupdate\data\db\tm, which is where you said you want it.
Was This Post Helpful? 0
  • +
  • -

#7 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Batch file - Unable to get databases to copy to correct file location

Posted 05 November 2008 - 10:04 AM

View Postgabehabe, on 5 Nov, 2008 - 08:49 AM, said:

Without looking over all your code, if it's all grouped together on a disc, why not just use XCOPY to copy it all to a backup dir?

Let me know if this isn't what you're looking for, like I said, I have't read over all your code:

REM Figure out which drive is the disc drive, I'll use E in my example
SET CDDRIVE=E:

XCOPY /e /v /y %CDDRIVE% "C:\Program Files\jkupdate\data\db\tm"


That will copy everything from your disc drive (drive E in my example) to C:\Program Files\jkupdate\data\db\tm, which is where you said you want it.


GREAT! Would I need to delete any of the code to make it work. Please see how I have inserted it.

:COPYDIR
:: If this dir contains DBs, copy the files to the JK Update Data folder.
:: Else copy all files in this dir to the hard disk.
echo ====== Directory %4
set DOCROOT=%3
SET CDDRIVE=E:

if '%4'=='"%CDDBDIR%"' goto :COPYDB1
if '%4'=='"_install"' goto :EOF
xcopy %CDDRIVE%\%4\* %3 /r /e %DATEFLAG% /f /i /s /h /y
cd %~P0
goto :EOF

:COPYDB1
for /D %%D in (%DATAROOT%\*) do %~F0 _copydb2 "%%D"
cd %~P0
goto :EOF

:COPYDB2
for /F %%F in (%2\*) do %~F0 _copydb3 "%%F" %%~nxF
cd %~P0
goto :EOF

:COPYDB3
if exist %CDDRIVE%\%CDDBDIR%\%3 XCOPY /e /v /y %CDDRIVE% "C:\Program Files\jkupdate\data\db\tm" %2 /r /e %DATEFLAG% /f /i /s /h /y
cd %~P0
goto :EOF


Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

#8 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1385
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Batch file - Unable to get databases to copy to correct file location

Posted 05 November 2008 - 11:30 AM

To be honest, I tend to find it difficult to read stuff like this. I can just write it. The main reason being that it's often specific your files, environment, etc. But looking at it, it seems OK.

The best way to make sure it works is just to test it. :)
Was This Post Helpful? 0
  • +
  • -

#9 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Batch file - Unable to get databases to copy to correct file location

Posted 05 November 2008 - 02:08 PM

View Postgabehabe, on 5 Nov, 2008 - 10:30 AM, said:

To be honest, I tend to find it difficult to read stuff like this. I can just write it. The main reason being that it's often specific your files, environment, etc. But looking at it, it seems OK.

The best way to make sure it works is just to test it. :)


I will test it out tomorrow. Thanks again for everything.
Was This Post Helpful? 0
  • +
  • -

#10 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Batch file - Unable to get databases to copy to correct file location

Posted 06 November 2008 - 07:02 AM

View Postknockkneed81, on 5 Nov, 2008 - 01:08 PM, said:

View Postgabehabe, on 5 Nov, 2008 - 10:30 AM, said:

To be honest, I tend to find it difficult to read stuff like this. I can just write it. The main reason being that it's often specific your files, environment, etc. But looking at it, it seems OK.

The best way to make sure it works is just to test it. :)


I will test it out tomorrow. Thanks again for everything.


Unfortunately it is still copying to the incorrect location. I need only the database to copy to the following destination C:Program Files\jkupdate\data\db\tm. The stuff in red are the modifications I made.

@echo off

set CDDRIVE=%~D0
set ROOTFILE=%CDDRIVE%\_root.txt
set CDDBDIR=_db
[color=#FF0000]set DATADIR="C:\Program Files\jkupdate\data\db\tm"[/color]


:: Check for command extensions before we start.
if cmdextversion 1 (echo.) else goto :NOCMDEXT

if '%1'=='' goto START
if '%1'=='/d' goto STARTDATE
if '%1'=='_copydir' goto COPYDIR
if '%1'=='_copydb2' goto COPYDB2
if '%1'=='_copydb3' goto COPYDB3

:: Print usage message and bail out.
echo Usage: %0 [/d]
goto :EOF


:STARTDATE
set DATEFLAG=/d

:START
:: Check for existence of the root file.
if not exist %ROOTFILE% goto :NOROOTFILE

:: Get the root folder name from the root file.
cd %CDDRIVE%\
for /F "delims=:" %%f in ('type %ROOTFILE%') do set ROOTDIR=%%f

:: Determine the destination directory for the data.
title Install JTDI Updates
echo Ready to begin install of JTDI updates.
pause
if '%CDDRIVE%'=='F:' goto SKIPF1
set HDDRIVE=f:
set DOCROOT=f:%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:: 2007-02-06:sc: JTDI 1.0 sites will be <drive>:\JTDI\<service>.  Adding check so that this install will work with both structures.
set DOCROOT=f:\JTDI%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:SKIPF1
if '%CDDRIVE%'=='E:' goto SKIPE1
set HDDRIVE=e:
set DOCROOT=e:%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:: 2007-02-06:sc: JTDI 1.0 sites will be <drive>:\JTDI\<service>.  Adding check so that this install will work with both structures.
set DOCROOT=e:\JTDI%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:SKIPE1
if '%CDDRIVE%'=='D:' goto SKIPD1
set HDDRIVE=d:
set DOCROOT=d:%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:: 2007-02-06:sc: JTDI 1.0 sites will be <drive>:\JTDI\<service>.  Adding check so that this install will work with both structures.
set DOCROOT=d:\JTDI%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:SKIPD1
if '%CDDRIVE%'=='C:' goto SKIPC1
set HDDRIVE=c:
set DOCROOT=c:%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:: 2007-02-06:sc: JTDI 1.0 sites will be <drive>:\JTDI\<service>.  Adding check so that this install will work with both structures.
set DOCROOT=c:\JTDI%ROOTDIR%
if exist %DOCROOT% goto SETDATAROOT

:SKIPC1
echo Could not find %ROOTDIR% nor \JTDI%ROOTDIR% directories on hard disk. Exiting.
pause
goto :EOF


:SETDATAROOT
if '%CDDRIVE%'=='F:' goto SKIPF2
set DATAROOT=f:%DATADIR%
if exist %DATAROOT% goto GENLIST

:SKIPF2
if '%CDDRIVE%'=='E:' goto SKIPE2
set DATAROOT=e:%DATADIR%
if exist %DATAROOT% goto GENLIST

:SKIPE2
if '%CDDRIVE%'=='D:' goto SKIPD2
set DATAROOT=d:%DATADIR%
if exist %DATAROOT% goto GENLIST

:SKIPD2
if '%CDDRIVE%'=='C:' goto SKIPC2
set DATAROOT=c:%DATADIR%
if exist %DATAROOT% goto GENLIST

:SKIPC2
set DATAROOT=''

:GENLIST
:: Generate a list of top-level dirs and reinvoke the program once for each dir.
cd %CDDRIVE%\
for /D %%D in (*) do %~F0 _copydir %HDDRIVE% %DOCROOT% "%%D" %DATAROOT%
cd %~P0
goto :EOF

:COPYDIR
:: If this dir contains DBs, copy the files to the JK Update Data folder.
:: Else copy all files in this dir to the hard disk.
echo ====== Directory %4
set [color=#FF0000]DATADIR=%3[/color]

if '%4'=='"%CDDBDIR%"' goto :COPYDB1
if '%4'=='"_install"' goto :EOF
xcopy %CDDRIVE%\%4\* %3 /r /e %DATEFLAG% /f /i /s /h /y
cd %~P0
goto :EOF

:COPYDB1
for /D %%D in (%DATAROOT%\*) do %~F0 _copydb2 "%%D"
cd %~P0
goto :EOF

:COPYDB2
for %%F in (%2\*) do %~F0 _copydb3 "%%F" %%~nxF
cd %~P0
goto :EOF

:COPYDB3
if exist %CDDRIVE%\%CDDBDIR%\%3 xcopy %CDDRIVE%\%CDDBDIR%\%3 [color=#FF0000]C:\%DATADIR%[/color] /r /e %DATEFLAG% /f /i /s /h /y
cd %~P0
goto :EOF



:NOCMDEXT
echo.
echo Command extensions not enabled. Exiting.
pause
goto :EOF

:NOROOTFILE
echo Root file "%ROOTFILE%" not found. Exiting.
pause
goto :EOF



This post has been edited by knockkneed81: 06 November 2008 - 07:05 AM

Was This Post Helpful? 0
  • +
  • -

#11 knockkneed81  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 52
  • Joined: 05-November 08

Re: Batch file - Unable to get databases to copy to correct file location

Posted 10 November 2008 - 07:34 AM

View Postgabehabe, on 5 Nov, 2008 - 10:30 AM, said:

To be honest, I tend to find it difficult to read stuff like this. I can just write it. The main reason being that it's often specific your files, environment, etc. But looking at it, it seems OK.

The best way to make sure it works is just to test it. :)



Hello

Hello
Was This Post Helpful? 0
  • +
  • -

#12 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1385
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: Batch file - Unable to get databases to copy to correct file location

Posted 10 November 2008 - 07:42 AM

Can you be a little more specific?

Tell me the structure of these discs~ Like I said, I can't test it.

Is it just the databases on the disc?

Example:
E:
--DB1
--DB2

Are they in subdirectories?

E:
--DB1
----DB1part1
----DB1part2
--DB2

Or are there additional files on the disc, as well as the databases?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1