Windows BAT: check for a specific file

I would like to check if there is an empty file in the .bat file of the file. Here is my broken script:

set dir="C:\test" set file="%dir%\fff.txt" cd %dir% if %file%%~zi == 0 exit ftp -s:"%dir%\ftp.action" exit 

Could you help me debug this, please?

+8
windows file batch-file
source share
3 answers

Or try using

 @echo off set "dir=C:\temp" set "file=%dir%\a.txt" call :CheckEmpty "%file%" goto :eof :CheckEmpty if %~z1 == 0 exit ftp -s:"%dir%\ftp.action" goto :eof 

The main difference is that I use a function call and use% ~ z1, since modifiers only work for parameters like% 1,% 2 ..% 9 or for loop parameters like %% a ...

+7
source share

batch solution using file comparison:

 type nul > blank fc myfile blank > nul if errorlevel 1 echo myfile is not empty 
+4
source share

Try the following:

  Const ForReading = 1 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("c:\boot.ini", ForReading) Dim arrFileLines() i = 0 Do Until objFile.AtEndOfStream Redim Preserve arrFileLines(i) arrFileLines(i) = objFile.ReadLine i = i + 1 Loop objFile.Close 
0
source share

All Articles