1.

Solve : delete zero byte files?

Answer»

I need some help I have a process that creates a file and another that will start other jobs based on the file existing however I need to delete the file if there is no data in it.  i.e. zero byte.

how do I delete a file if it has zero BYTES in a BATCH command? :-? :-?you can create an empty file, and use FC command (CHECK out fc /? ) to compare

  set zerofile=zerobyte
  copy nul %zerofile% >nul
  for /f "delims=" %%a in ('dir/s/b/a-d') do (
    fc %zerofile% "%%a" >nul && del "%%a"
  )
  del %zerofile%I do not understand what you are telling me :-?  

I already have a file that may or may not be zero bytes.

when it is zero bytes I need to delete it so my next job will not run. Code: [Select]set zerofile=zerobyte
  copy nul %zerofile% >nul
This will copy a 0 byte file and name it as zerobyte. This file will be used later in the for loop to compare
file sizes

Code: [Select]  for /f "delims=" %%a in ('dir/s/b/a-d') do (
    fc %zerofile% "%%a" >nul && del "%%a"
  )
This will go to the directory where your files are, and compare their sizes with the file zerobyte
if they are 0 bytes,then delete

thank you that worked prefectly Or without creating the 0 byte file or calling FC, you can just check the size of the file like:
Code: [Select]  for /f "delims=" %%a in ('dir/s/b/a-d') do (
    if %%~za==0 del "%%a"
  )I have almost the same situation.
one file is zipped each day and it happends that ziping doesn't go well and I have 0 bytes zipped file.
So how can I delete that zipped file and start zipping original file again. In the same folder is more files so it must be file created today, which is zipped again.
all is in the folder d:/backupdb

batch for zipping file is
Code: [Select]FOR %%i IN (*.bak) DO 7z.exe a "%%~ni.7z" "%%i" Code: [Select]FOR %%i IN (*.bak) DO (
FOR %%G in (%%~ni.7z) DO IF "%%~zG"=="0" del "%%~G" 2>nul
7z.exe a "%%~ni.7z" "%%i"
)Start your own thread, don't try and re-use old ones.



Discussion

No Comment Found