Need to edge out the competition for your dream job? Train for certifications today.
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
for %R in (filename.txt) do if %~zR equ 0 del filename.txt
Open in new window
for %%R in (filename.bat) do if %%~zR equ 0 del filename.txt
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
strFilePath = "<insert path to file here>"
Set oFSO = CreateObject("Scripting.FileSystemObject")
if oFSO.FileExists(strFilePath) then
Set oFile = oFSO.GetFile(strFilePath)
strLine = ""
linecount = 0
blnShouldDelete = True
Set ts = oFile.OpenAsTextStream(1, -2)
Do While ts.AtEndOfStream <> True
linecount = linecount + 1
strLine = ts.ReadLine
if Len(strLine) > 0 then
blnShouldDelete = False
if (linecount = 0 Or linecount = 1) And blnShouldDelete = True then
set oFSO = Nothing
REM Delete file if it exists, and is empty (0 bytes length)
if exist "sample.txt" (
for %%A in ("sample.txt") do (
if %%~zA EQU 0 (
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment