Batch Script - tjek folder, skriv log og upload fil til ftp - loop ?
Jeg har oprettet dette script som tjekker en bestemt mappe om den indeholder filer, hvis den gør skal der skrives til en log og denne log skal uploades til ftp.Scriptet fungerer 99% men efter at have tilføjet ændring af datoformat for at finde den folder der skal tjekkes, så er det som om at scriptet looper en enkelt gang og sender fil til ftp uanset om folder et tom eller ej ? I denne situation er folderen tom og derfor skal scriptet ikke gå videre til ftp delen. (filen den uploader er en gammel fil der stadig ligger i log folderen)
Har stiret mig blind på koden - noget input ?
SÅDAN SER SCRIPT UD:
!:--- ændrer datoformat som skal bruges til at finde folder ---
echo %date%
set year=%date:~-4%
echo year=%year%
set month=%date:~4,2%
echo month=%month%
set day=%date:~7,2%
echo day=%day%
set foldername=%year%%month%%day%
echo %foldername%
!:--- tjekker om der ligger filer i folderen ---
@echo off
for /F %%i in ('dir /b "D:\program\Server\Transactions\Normal\%foldername%\*.*"') do (
echo %Date%, %Time%, %COMPUTERNAME%, Normal folder is NOT empty >> D:\installationfiles\normal\%COMPUTERNAME%.txt
goto :FTP
)
echo Folder is empty
:FTP
@ftp -i -s:"%~f0"&GOTO:EOF
open ftp.ftpserver.com
brugernavn
password
!:--- FTP commands below here ---
lcd D:\installationfiles\normal
cd /WN/Normal_Check
binary
mput "*.txt"
disconnect
bye
SÅDAN SER DET UD NÅR FILES KØRES:
D:\Installationfiles>checkandupload.cmd
D:\Installationfiles>echo Tue 09/13/2011
Tue 09/13/2011
D:\Installationfiles>set year=2011
D:\Installationfiles>echo year=2011
year=2011
D:\Installationfiles>set month=09
D:\Installationfiles>echo month=09
month=09
D:\Installationfiles>set day=13
D:\Installationfiles>echo day=13
day=13
D:\Installationfiles>set foldername=20110913
D:\Installationfiles>echo 20110913
20110913
Folder is empty
ftp> echo %date%
Invalid command.
ftp>
ftp> set year=%date:~-4%
Invalid command.
ftp> echo year=%year%
Invalid command.
ftp>
ftp> set month=%date:~4,2%
Invalid command.
ftp> echo month=%month%
Invalid command.
ftp>
ftp> set day=%date:~7,2%
Invalid command.
ftp> echo day=%day%
Invalid command.
ftp>
ftp> set foldername=%year%%month%%day%
Invalid command.
ftp>
ftp> echo %foldername%
Invalid command.
ftp>
ftp> @echo off
Invalid command.
ftp>
ftp> for /F %%i in ('dir /b "D:\TPDotnet\Server\Transactions\Normal\%foldername%
\*.*"') do (
Invalid command.
ftp> echo %Date%, %Time%, %COMPUTERNAME%, Normal folder is NOT empty >> D:\in
stallationfiles\normal\%COMPUTERNAME%.txt
Invalid command.
ftp> goto :FTP
Invalid command.
ftp> )
Invalid command.
ftp>
ftp> echo Folder is empty
Invalid command.
ftp>
ftp> :FTP
Invalid command.
ftp>
ftp> @ftp -i -s:"%~f0"&GOTO:EOF
Invalid command.
ftp> open ftp.ftpserver.com
Connected to ftp.ftpserver.com.
220 Please enter your login name now.
User (ftp.ftpserver.com:(none)):
331 Password required for Retail
230 User Retail logged in.
ftp> !:--- FTP commands below here ---
ftp> lcd D:\installationfiles\normal
Local directory now D:\installationfiles\normal.
ftp> cd /WN/Normal_Check
250 "/WN/Normal_Check" is current directory.
ftp> binary
200 Type set to IMAGE.
ftp> mput "*.txt"
200 PORT command successful
150 Opening BINARY data connection for /WN/Normal_Check/BSR00253.txt (STREAM)
226 Transfer finished successfully. Data connection closed.
ftp: 204 bytes sent in 0.00Seconds 204000.00Kbytes/sec.
ftp> disconnect
221 Goodbye.
ftp> bye
D:\Installationfiles>