How to open all the text files (.txt) In a directory , which have some data in it (size not 0 ) using batch script.
Thanks in advance.
How to open all the text files (.txt) In a directory , which have some data in it (size not 0 ) using batch script.
Thanks in advance.
for %%a in ("c:\folder\*.txt") do if %%~za gtr 0 start "" "%%~fa"
The for
command will iterate over the files matched by the in
clause. For each file found, the code in the do
clause is executed with a reference to the file stored in the replaceable parameter (%%a
in this sample)
%%~za
is the size of the file and %%~fa
is the file reference with the full path. So, the code means: for each txt file in the indicated folder, if the size of the file is greater than 0, start the file with whatever application associated to it
note: start
command takes the first quoted argument as the title of the started window. As the file reference is quoted to prevent problems with spaces, the empty quotes are included to avoid the file reference being readed as a title
This will explain how to loop files in a batch file and conditionally do something based on file size.
How can I check the size of a file in a Windows batch script?
You can then modify it to use notepad or another program to open the file.