@echo off

SETLOCAL ENABLEDELAYEDEXPANSION
set backupFilename=%DATE:~6,4%%DATE:~3,2%%DATE:0,2%


::   iF YOU HAVE LONG FILE NAME IN NETWORK PATH MORE THAN 255, IT might not work. Use the GUI app instead.

:Choice

echo Enter your Information Below...
                
set /P Reg= Enter the ftp path or network path to copy data from  : 
set /P Amount= How many files approximately do you want to download  :
set /P Destin= Enter Destination to copy the file  :
set /P ext= Enter the extension files :
net use B: /delete /Y
net use B: "%REG%"  mypassword /user:mydomain\myusername /persistent:no 

jstack %id% > jstack.txt

mkdir "%Destin%"

:: sample to map with password net use Z: \\Windos\g$ P@ssw0rd /user:Mynetdomain\Sysadmin /persistent:yes
:: * Means to assign to any drive letter net use * /delete /yes or net use \\servername or ipaddress\MyProject /delete /yes 





:: These 2 lines script copy only newest file. It works very well (Not for good for project newest and last 10 days download) 



:: These will copy the newest file + and the aproximate files you want for last 10 days



DIR "%Reg%\%ext%" /B /O:-d /T:W>%temp%\dir.txt

SET count=0

FOR /F %%I in (%temp%\dir.txt) DO CALL :_Copy %%I


:_Copy

SET file=%1

SET /a count=%count%+1
IF %count% GTR %Amount% net use B: /delete /Y
IF %count% GTR %Amount% goto :EOF

xcopy "%Reg%\%file%" "%Destin%" /v /y




if errorlevel 255 echo user_stopped_the_process
 
if errorlevel 8 echo  not_enough_memory 

if errorlevel 7 echo  command_line_error 

if errorlevel 2 echo  fatal_error

if errorlevel 1 echo  OK is warning
if errorlevel 0 echo   very OK successful withoput warning or error 


 



timeout 3
:ok




:: This will come out with Msgbox, commented out not neccessary 






  