:: need to copy \\Myserverdir\File.txt to C:\mydir\Test_(date_creation).txt
setlocal
:: the following are what I used to test - change to yours!
set folder=\\fils\FTP_Web\OUT
set file=TAB_L0928.txt
set target=\\roms\workarea$\FSRM107\Ges\DATABASE\CEC
:: get the file's date as dd/mm/yyyy
for /f "tokens=1" %%a in ('dir "%folder%\%file%" ^| find /i "%file%"') do set filedate=%%a
:: change the date to yyyymmdd
set date_created=%filedate:~-4,4%%filedate:~-7,2%%filedate:~0,2%
:: perform the copy, if the file is not present in the target
if not exist "%target%\L0928-%date_created%.txt" ^
copy "%folder%\%file%" "%target%\L0928-%date_created%.txt"
:: check on the copied file
dir "%target%\L0928-%date_created%.txt"
endlocal
exit /b 0
please check this batch, work.... but have error during the code run
Moderator: DosItHelp
Re: please check this batch, work.... but have error during the code run
Rather try ROBOCOPY if you want to copy files using network paths.
Steffen
Steffen
Re: please check this batch, work.... but have error during the code run
If you use RoboCopy you will unfortunately need to copy and rename though.
Based on a guess at your date output, (09/01/2017), this may work:
Based on a guess at your date output, (09/01/2017), this may work:
Code: Select all
@Echo Off
Set "folder=\\fils\FTP_Web\OUT"
Set "file=TAB_L0928.txt"
Set "target=\\roms\workarea$\FSRM107\Ges\DATABASE\CEC"
Set "new=L0928-%%D%%C%%B.txt"
For /F "EOL= Delims=" %%A In ('Dir "%folder%\%file%"'
) Do For /F "Tokens=1-3 Delims=/ " %%B In ("%%A"
) Do If Not Exist "%target%\%new%" (RoboCopy "%folder%" "%target%" "%file%"
Ren "%target%\%file%" "%new%")
Re: please check this batch, work.... but have error during the code run
Compo wrote:If you use RoboCopy you will unfortunately need to copy and rename though.
Based on a guess at your date output, (09/01/2017), this may work:Code: Select all
@Echo Off
Set "folder=\\fils\FTP_Web\OUT"
Set "file=TAB_L0928.txt"
Set "target=\\roms\workarea$\FSRM107\Ges\DATABASE\CEC"
Set "new=L0928-%%D%%C%%B.txt"
For /F "EOL= Delims=" %%A In ('Dir "%folder%\%file%"'
) Do For /F "Tokens=1-3 Delims=/ " %%B In ("%%A"
) Do If Not Exist "%target%\%new%" (RoboCopy "%folder%" "%target%" "%file%"
Ren "%target%\%file%" "%new%")
Sorry for delay very busy...
tks for code! work great.
but...
this code overwrite the file if in destination dir just exists the file with same name?
Tks.
Re: please check this batch, work.... but have error during the code run
You can add an additional IF EXIST clause to the code. Also RoboCopy doesn't overwrite files if they are the same, if you wish to preserve one or other of those copies then there are a range of options available.sal21 wrote:Sorry for delay very busy...
tks for code! work great.
but...
this code overwrite the file if in destination dir just exists the file with same name?
Tks.
Type ROBOCOPY /? at the cmd.exe window prompt for those options.
Re: please check this batch, work.... but have error during the code run
Compo wrote:You can add an additional IF EXIST clause to the code. Also RoboCopy doesn't overwrite files if they are the same, if you wish to preserve one or other of those copies then there are a range of options available.sal21 wrote:Sorry for delay very busy...
tks for code! work great.
but...
this code overwrite the file if in destination dir just exists the file with same name?
Tks.
Type ROBOCOPY /? at the cmd.exe window prompt for those options.
ok...
found this option /IS, but were in your code?
tks.