UtterAccess.com
We have detected that you are using an unsupported web browser. We recommend you to upgrade your web browser to get the most from UtterAccess forums.
Why should and how can I upgrade?
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

2 Pages V   1 2 >  
Reply to this topicStart new topic
> Copy File With Current Date In Dos, Any Version    
 
   
bakersburg9
post Oct 12 2011, 12:05 PM
Post #1

UtterAccess Ruler
Posts: 4,375
From: Downey, CA



I have a file on my local drive I want to copy to my network drive, and save it with the current date as an extension and do this in DOS using a batch file - is this possible ?
My file name is ProjectTracker.mdb on my C: drive - I want to copy it to the P: drive, something like ProjectTracker_Copy_2011_10_12.mdb if I'm running my batch file on Oct 12th, and also I would want to write another line of code deleting previous files, like 10 days back, and any earlier than that
Go to the top of the page
 
+
Jeff B.
post Oct 12 2011, 12:24 PM
Post #2

UtterAccess VIP
Posts: 8,736
From: Pacific NorthWet



Here's a line of code I use to make a copy of an .mdb file in a 'backup' folder...
FileCopy strLocalVersionName, Left(strLocalVersionName, Len(strLocalVersionName) - 15) & "\backup\" & Format(Now(), "yyyymmdd@hhmm") & strFileName
Take a look in Access HELP for the exact syntax of the FileCopy command.
... by the way, if you use the date in yyyymmdd format as a PREFIX, you can easily sort/find the date-of-backup...
Go to the top of the page
 
+
bakersburg9
post Oct 12 2011, 12:26 PM
Post #3

UtterAccess Ruler
Posts: 4,375
From: Downey, CA



I'm sorry, you will have to 'dumb it down' - my question was for creating a batch file using MS-DOS - where exactly did you do this ?
Go to the top of the page
 
+
Jeff B.
post Oct 12 2011, 12:28 PM
Post #4

UtterAccess VIP
Posts: 8,736
From: Pacific NorthWet



Sorry, I was focusing on MS Access. Hopefully one of the DOS wizards can help with a batch file...
Go to the top of the page
 
+
Aquadevel
post Oct 12 2011, 12:30 PM
Post #5

UtterAccess VIP
Posts: 6,902
From: Earth...



Just create the batch file in NotePad, and save it with a .bat extension
Go to the top of the page
 
+
bakersburg9
post Oct 12 2011, 12:40 PM
Post #6

UtterAccess Ruler
Posts: 4,375
From: Downey, CA



Yes, I know how to create a batch file, I just need help with syntax - I don't want to just create a copy in another folder and call it "MyFilename_Copy.accdb" - I want to call give it an extension with the current date, like "MyFilename_Copy_2011_10_12.accdb" if the scheduled job (I'm using scheduler to run my batch files) runs on Oct 12, for example
Go to the top of the page
 
+
theDBguy
post Oct 12 2011, 12:44 PM
Post #7

Access Wiki and Forums Moderator
Posts: 58,559
From: SoCal, USA



Hi Steve,
ardon me for jumping in... If I recall correctly, your OS is Windows and not MS DOS. If so, maybe you could consider using VBScript instead of a Batch file because what you want to do is a little bit complicated for what DOS commands alone can do.
Just my 2 cents... 2cents.gif
Go to the top of the page
 
+
bakersburg9
post Oct 12 2011, 12:51 PM
Post #8

UtterAccess Ruler
Posts: 4,375
From: Downey, CA



Wow, I wouldn't have a CLUE where to start on that - I know that DOS can be dicey at times - although I have a co-worker that does this and it works fine for him - I just set up a batch file to copy an .mdb and an .accdb, and it worked fine - doesn't mean something couldn't go wrong in the future
Go to the top of the page
 
+
theDBguy
post Oct 12 2011, 12:58 PM
Post #9

Access Wiki and Forums Moderator
Posts: 58,559
From: SoCal, USA



Hi,
That I meant about "complicated" was that most DOS commands are geared to work towards files - not strings. In your requirement, you want to use the "current date" with the file name. Unfortunately, the DOS command to return the current date will give you an invalid file name because it includes "invalid" characters. I am not sure which combination of DOS commands you can use to parse the result of the current date to make it valid as a file name.
That's all I'm saying...
On the other hand, VBScript includes functions similar to VBA functions that you are already familiar with. You will be able to use functions like Left() or Mid() to construct a valid file name from the current date.
Just my 2 cents... 2cents.gif
Go to the top of the page
 
+
bakersburg9
post Oct 12 2011, 01:07 PM
Post #10

UtterAccess Ruler
Posts: 4,375
From: Downey, CA



dbGuy - I realize that, but I wouldn't know where to start with VBscript
Go to the top of the page
 
+
Bob G
post Oct 12 2011, 01:27 PM
Post #11

UtterAccess VIP
Posts: 10,461
From: CT



I had to dig thru some stuff but found a basis to start with.
o test this. create a text file on the C:\ drive called test.txt just put some random words in it.
create a new text file with the below in it and give it an extension of .bat
run it and then see if that is what you are looking for as a starting point.
the key is the line that says..set newname=
CODE
CD /D %homedrive%\%homepath%\Desktop
Set CURRDATE=%TEMP%\CURRDATE.TMP
Set CURRTIME=%TEMP%\CURRTIME.TMP
DATE /T > %CURRDATE%
TIME /T > %CURRTIME%
Set PARSEARG="eol=; tokens=1,2,3,4* delims=/, "
For /F %PARSEARG% %%i in (%CURRDATE%) Do SET YYYYMMDD=%%l%%k%%j
Set PARSEARG="eol=; tokens=1,2,3* delims=:, "
For /F %PARSEARG% %%i in (%CURRTIME%) Do Set HHMM=%%i%%j%%k
set newname=test_%YYYYMMDD%-%HHMM%.txt
copy c:\test.txt c:\%newname%
exit
Go to the top of the page
 
+
theDBguy
post Oct 12 2011, 01:38 PM
Post #12

Access Wiki and Forums Moderator
Posts: 58,559
From: SoCal, USA



Okay, think of it as a hybrid between a batch file and VBA. You can use Notepad to enter the commands and save the file with a .vbs extension.
o see what commands are available for you, take a look at this list.
For the basics of creating a script file, take a look at this YouTube video.
(Sorry, I couldn't find a better example for you.)
Cheers
Go to the top of the page
 
+
theDBguy
post Oct 12 2011, 01:46 PM
Post #13

Access Wiki and Forums Moderator
Posts: 58,559
From: SoCal, USA



Hi Bob,
forgot that FOR works for Strings too. Thanks. tical-align:middle" emoid=":thumbup:" border="0" alt="thumbup.gif" />
Go to the top of the page
 
+
bakersburg9
post Oct 12 2011, 01:46 PM
Post #14

UtterAccess Ruler
Posts: 4,375
From: Downey, CA



dbGuy and BobG - I will try all that, but in the meantime, I found this - you CAN do it in DOS
ClickHere
Ocame close enough to where I know it can be done
There is my batch file code, which I got from this site (the part in BOLD):
copy "C:\Documents and Settings\E115812\My Documents\ProjectTracker.mdb" A:\ProjectTracker_copy.mdb
echo %date:~10,4%%date:~7,2%%date:~4,2%
ren A:ProjectTracker_Copy.mdb ProjectTracker_Copy_%date:~10,4%%date:~7,2%%date:~4,2%.mdb

When I ran it, it produced this:
ProjectTracker_Copy_012-.mdb
so I'm close - I just want
ProjectTracker_Copy_2011_10_012.mdb if ran on October 12th....
so at least I know it is possible - I will try your deal though - I'm always interested in learning new things
Go to the top of the page
 
+
bakersburg9
post Oct 12 2011, 02:00 PM
Post #15

UtterAccess Ruler
Posts: 4,375
From: Downey, CA



OK, I found this:
et mydate=%date:~4,2%%date:~7,2%%date:~10,4%
set datestr=%d:~6,4%%d:~3,2%%d:~0,2%
set y=%d:~6,4%
set m=%d:~3,2%
set d=%d:~0,2%
echo %date:~10,4%%date:~7,2%%date:~4,2%
apparently, it works like a mid function - for the Y, return a 4 character string starting with the 6th character, for the m, return a 2 character string starting with the 3rd character, for the d, return a 2 character string starting with the first position - but I can't get the syntax right !
Go to the top of the page
 
+
theDBguy
post Oct 12 2011, 02:13 PM
Post #16

Access Wiki and Forums Moderator
Posts: 58,559
From: SoCal, USA



Hi,
don't think I ever said it was not possible - just a bit complicated. As you and Bob have pointed out, the FOR command can be used to parse the date into separate sections for the filename.
But I still think that using functions built for this purpose would be a little bit easier, especially since your users (or you) are not really working in a DOS only environment.
Just my 2 cents... 2cents.gif
Go to the top of the page
 
+
theDBguy
post Oct 12 2011, 02:34 PM
Post #17

Access Wiki and Forums Moderator
Posts: 58,559
From: SoCal, USA



Hi,
would try something like
set myfile=ProjectTracker_Copy
set myfile=%myfile%_%date:~10,4%
set myfile=%myfile%_%date:~7,2%
set myfile=%myfile%_%date:~4,2%
set myfile=%myfile%.mdb
ren ProjectTracker_Copy.mdb %myfile%
(untested)
Hope that helps...
Go to the top of the page
 
+
CyberCow
post Oct 13 2011, 08:47 AM
Post #18

UdderAccess Admin + UA Ruler
Posts: 19,096
From: Upper MI



Here's a copy of the vbScript I use to back up data with time stamped file names. It also logs the the amount of time it took to conduct the back up in a text file named: "c:\Scripts\MonthlyTiming.txt"
Please note that this code is executed from the Task Scheduler on the server . . . . please feel free to alter as you wish.
Olearned vbscripting from the Scripting Guy
CODE
'// VBScript.
Option Explicit
Dim oFSO, oSHL, ln '// FileSystemObject, Shell, Source, Destination
Dim StTime, EndTime, TotTime
dim filetxt, getname, path
Dim flnm
' Filename: C:\Scripts\PCIData_Monthly_Inv.vbs
'// On Error Statement
On Error Resume Next
    Err.clear
StTime = Timer
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oSHL = CreateObject("WScript.Shell")
Set filetxt = oFSO.CreateTextFile("c:\Scripts\MonthlyTiming.txt", True)
path = oFSO.GetAbsolutePathName("c:\Scripts\MonthlyPCI_Data_BU_Timing.txt")
getname = oFSO.GetFileName(path)
flnm = "H:\PCIData\pci_data_" & Left(Date,InStr(1,Date,"/")-1) & "-" & Right(Date,4) & ".mdb"

' COPY DATA From 'myServerName\Access Data' to SmelterH (ext drive)
ln = 100
oFSO.CopyFile "D:\Access Data\pci_data.mdb",flnm
ln = 5555
'Wscript.echo "PCIData Copying Complete!"
EndTime = Timer
TotTime = (EndTime-StTime)/60
filetxt.WriteLine("Monthly, " & Date & " backup runtime in Minutes: " & TotTime)
filetxt.Close
WScript.Quit
'// Debug:
If Err <> 0 Then  
MsgBox "Error:" & CStr(Err.Number) & " - " & Err.Description & " - Ooops! - at line " & ln
  Else
'// Show MsgBox: ("Text", NumberOfSeconds, "Title" and vbOK(0) button + vbInformation(64) icon)
oSHL.Popup "Backup complete...", 10 ,"Confirmation...", 0 + 64
End If
hope this helps
Go to the top of the page
 
+
bakersburg9
post Oct 13 2011, 10:28 AM
Post #19

UtterAccess Ruler
Posts: 4,375
From: Downey, CA



I still don't understand where you PUT this code
Go to the top of the page
 
+
theDBguy
post Oct 13 2011, 10:34 AM
Post #20

Access Wiki and Forums Moderator
Posts: 58,559
From: SoCal, USA



Hi,
o you mean the YouTube video I showed you didn't help?
Basically, you copy and paste Moo's code into a Text file using Notepad. But when you save it, give it a .vbs extension. You can then double-click on that file or execute it in the Task Scheduler like Moo did.
Hope that helps...
Go to the top of the page
 
+

2 Pages V   1 2 >
Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Search  ·  Go to Top  ·  Lo-Fi Version Time is now: 31st October 2014 - 09:27 PM