batch-fileexportdumporacle-export-dump

Problems setting timestamp on for naming a file


I want to set the name of a file that will be generated automatically by adding a timestamp to its name.

the batch file is as follows:

echo export database for HR account
SET YYYYMMDD_HHMMSS=%DATE:~6,4%%DATE:~0,2%%DATE:~3,2%_%TIME:~0,2%%TIME:~3,2%
exp hr/esprit parfile=D:\exp_imp_4DS1\parfile_exp.par
rem pause end of export

parfile_exp.par:

FILE=D:\exp_imp_4DS1\hr_%YYYYMMDD_HHMMSS%.dmp
GRANTS=Y
INDEXES=Y
ROWS=Y
COMPRESS=Y

Executing the bat file gives me this error:

EXP-00028: failed to open D:\exp_imp_4DS1\hr_/28/Fr 1_1136.dmp for write

Solution

  • You should try with WMIC to get date independent of user settings date


    @echo off
    Call:ReportName
    echo %Report%
    pause & exit
    ::*********************************************************************************
    :ReportName
    for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set "dt=%%a"
    set datestamp=%dt:~0,8%
    set timestamp=%dt:~8,6%
    set YYYY=%dt:~0,4%
    set MM=%dt:~4,2%
    set DD=%dt:~6,2%
    set HH=%dt:~8,2%
    set Min=%dt:~10,2%
    set Sec=%dt:~12,2%
    set "stamp=%YYYY%%MM%%DD%_%HH%%Min%%Sec%"
    Set "Report=%~dp0hr_%stamp%.dmp"
    Exit /b
    ::*********************************************************************************