Announcement

Collapse
No announcement yet.

Batch file xcopy using %date%

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Batch file xcopy using %date%

    Click image for larger version  Name:	batch.png Views:	1 Size:	13.5 KB ID:	812462
    Daily, weekly, or monthly folder
    Code:
    FUNCTION PBMAIN AS LONG
     MakeBackupBatchFile
     SHELL "junk.bat"
    END FUNCTION
    
    SUB MakeBackupBatchFile
     LOCAL h AS LONG
     h = FREEFILE
     OPEN "junk.bat" FOR OUTPUT AS #h
     PRINT #h,"@echo off
     PRINT #h,"echo Date full    %date%
     PRINT #h,"echo Date 8-byte  %date:~4,2%-%date:~7,2%-%date:~12,2%
     PRINT #h,"echo Week day     %date:~0,3%
     PRINT #h,"echo Month        %date:~4,2%
     PRINT #h,"echo Day          %date:~7,2%
     PRINT #h,"echo Year         %date:~10,4%
     PRINT #h,"echo Year short   %date:~12,2%
     PRINT #h,"echo Just numbers %date:~4,2%%date:~7,2%%date:~10,4%
    
     'xcopy by set mydate to something from above
     PRINT #h,"set mydate=%date:~4,2%-%date:~7,2%-%date:~12,2%
    
     PRINT #h,"@echo on"   'view the xcopy fail because of invalid destination drive B
     PRINT #h,"xcopy /e/d/f/r/y *.* B:\backup\%mydate%\*.*
     PRINT #h,"@echo off"
     PRINT #h,"pause
     CLOSE #h
    END SUB

  • #2
    I'd much rather use an ISO date so that the directories sort logically

    Code:
     PRINT #h,"set mydate=%date:~10,4%-%date:~7,2%-%date:~4,2%
    Click image for larger version  Name:	ISODateBat.jpg Views:	0 Size:	19.4 KB ID:	812467

    Comment

    Working...
    X