I am reading up on Windows batch files and have not yet seen what I need.
1) How do I check to see if a file exists?
2) How do I wait to keep the batch file from using too much cpu time?
Here is the basic concept:
echo starting ftp processor
cd c:\ftpdir
:top
if exists put*.txt // how do I check for this
ftp -sut_<postfix>.txt // this should be dash s colon put, no happy face intended
del put_<postfix>.txt
end if // for if exists put.txt
sleep 6000 // how do I wait for six seconds
goto top
An existing program creates files such as put_abc.txt in the directory. The file contains the specs to perform an FTP operation. The file name may be put_def.txt, put_efg.txt, etc.
I see the "find" command, but have not yet figured out how to use it in this context.
From looking at the else statement, its a single line command so I may have to do something like:
if exists put*.txt
call putfile.bat
Is that correct?
I just discovered PowerShell. Is PowerShell much better?
After more readings, I developed two files for my ftp operations as shown below. The get getlock operation is successful.
The problem is that after doing the getlock ftp operation, my command window is left in ftp mode showing the ftp prompt. It does not execute the if exist statement. When I type in "quit" to get out of the ftp mode, the batch file seems to continue running but does not do what I expect. I have tried putting a bye and quit command in both the batch file and in the ftp control file to no avail. Here are the two files:
batch file:
@echo on
echo ftp test batch
ftp -v -s:getlock.txt
if exist lock.txt (
echo.
echo COMPUTER BUSY, WILL TRY LATER
echo.
) else (
for %%a in (put*.txt ) do (
echo.
echo putting some files
ftp -v s:%%a
echo.
)
)
contents of getlock.txt
open <my server>
<my user id>
<my password>
cd incoming
get lock.txt
Thanks for your time.
New discovery, for me that is.
If the file lock.txt exists on the server I don't want to send data. However, the attempt to do an FTP get for the file lock.txt from the other computer always creates a local file called lock.txt. The size of the local file is 0 (zero bytes) if the file on the server does not exist.
Is there a way I can supress that file creation. If not, how do I test for a zero length file in a batch file?
Regardless, thank you to Saxon for consolodating my posts. I appreciate the links, but I cannot buy things to make this project work. I just have to make it work. I will keep looking. Thanks for your time.
1) How do I check to see if a file exists?
2) How do I wait to keep the batch file from using too much cpu time?
Here is the basic concept:
echo starting ftp processor
cd c:\ftpdir
:top
if exists put*.txt // how do I check for this
ftp -sut_<postfix>.txt // this should be dash s colon put, no happy face intended
del put_<postfix>.txt
end if // for if exists put.txt
sleep 6000 // how do I wait for six seconds
goto top
An existing program creates files such as put_abc.txt in the directory. The file contains the specs to perform an FTP operation. The file name may be put_def.txt, put_efg.txt, etc.
I see the "find" command, but have not yet figured out how to use it in this context.
From looking at the else statement, its a single line command so I may have to do something like:
if exists put*.txt
call putfile.bat
Is that correct?
I just discovered PowerShell. Is PowerShell much better?
After more readings, I developed two files for my ftp operations as shown below. The get getlock operation is successful.
The problem is that after doing the getlock ftp operation, my command window is left in ftp mode showing the ftp prompt. It does not execute the if exist statement. When I type in "quit" to get out of the ftp mode, the batch file seems to continue running but does not do what I expect. I have tried putting a bye and quit command in both the batch file and in the ftp control file to no avail. Here are the two files:
batch file:
@echo on
echo ftp test batch
ftp -v -s:getlock.txt
if exist lock.txt (
echo.
echo COMPUTER BUSY, WILL TRY LATER
echo.
) else (
for %%a in (put*.txt ) do (
echo.
echo putting some files
ftp -v s:%%a
echo.
)
)
contents of getlock.txt
open <my server>
<my user id>
<my password>
cd incoming
get lock.txt
Thanks for your time.
New discovery, for me that is.
If the file lock.txt exists on the server I don't want to send data. However, the attempt to do an FTP get for the file lock.txt from the other computer always creates a local file called lock.txt. The size of the local file is 0 (zero bytes) if the file on the server does not exist.
Is there a way I can supress that file creation. If not, how do I test for a zero length file in a batch file?
Regardless, thank you to Saxon for consolodating my posts. I appreciate the links, but I cannot buy things to make this project work. I just have to make it work. I will keep looking. Thanks for your time.