Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I need a batch file to find and rename any file in a directory that is bigger than 7k. I have a materials directory that posts a file out every hour and if it is larger than 7k it is most likely a file in error.

@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
if %%~Za gtr 7000 echo ren %%a blabla
)
=====================================
If at first you don't succeed, you're about average.M2

It looks like it is working but it is not renaming the files. Also, I realized I can have more than one file within the day in error so I thought moving the files to a different directory might be a better idea. I changed the script to the following however it doesn't seem to be working either - it echos that it is moving the files but it doesn't do it.
@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (if %%~Za gtr 7000 echo move I:\materials\testing\%%a I:\materials\testing\hold)Sorry for my ignorance, I used to be pretty good at creating batch files back in the old DOS days, but things have kind of changed.

remove the ECH which preceeds the MOVE.
=====================================
If at first you don't succeed, you're about average.M2

Once again, excuse my ignorance. Works like a charm. Thanks, you don't know how many man hours you just saved. I work at a hospital and anything that saves times can be better spent on patient care.

All right, hate to bug you again, but...
Batch file works great, but I also have another batch file called - mail.bat that has the following in it:
Sendemail.exe -f x.x@x.x-o reply-to=x.x@x.org -t x.x@x.x -cc x.x@x.x -u "Material File Size Error" -m "Please check the \Materials\Hold directory as there is a file size error." -s smtp.x.org
I tried to incorporate this into the FOR command in your batch file to call it up and e-mail me when it finds a file to move. Apparently I am not that smart. I cannot figure out how to tag it onto the IF statement you used with the FOR command.
@echo off
setLocal EnableDelayedExpansion
for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (if %%~Za gtr 7000 move \\sjs2kcommoncl\cathlab$\materials\%%a \\sjs2kcommoncl\cathlab$\materials\hold)

Hi,
Last things first. If those emails are real, you should edit that reply and clear them out. Sadly, there are web bots lurking here.
::========================================
@echo off
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
if %%~Za gtr 7000 (
set error=y
move bla bla
)
)if !error! equ y Sendemail.exe bla bla
=====================================
If at first you don't succeed, you're about average.M2

Doesn't seem to be running the "if !error! equ y" section when it encounters a file gtr 7000. I have tried making changes to no avail.
@echo on
setLocal EnableDelayedExpansionfor /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
if %%~Za gtr 7000 (
set error=y
move C:\Test\%%a C:\Test\Hold
)
)if !error! equ y Sendemail.exe bla bla
also can I use "call mail.bat" instead of putting the whole Sendemail.exe command line in?
Your help has been invaluable.

Yes, you can "call mail.bat".
::============================I don't see why it's not working. I added ECHO and got this out put:
::==
move C:\Test\ONE.TAB C:\Test\Hold
move C:\Test\ONE.TAG C:\Test\Hold
Sendemail.exe bla bla
=====================================
If at first you don't succeed, you're about average.M2

Try this:
::==================================
@echo off
setLocal EnableDelayedExpansionpushd c:\temp
for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
if %%~Za gtr 7000 (
set error=y
move %%a C:\Test\Hold\
)
)if !error! equ y call mail.bat
=====================================
If at first you don't succeed, you're about average.M2

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |