Computing.Net > Forums > Windows XP > Need a batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Need a batch file

Reply to Message Icon

Name: Dr.Gonzo
Date: July 31, 2008 at 07:50:16 Pacific
OS: xp
CPU/Ram: intel 1gb
Product: dell
Comment:

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.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: July 31, 2008 at 08:09:13 Pacific
Reply:

@echo off
setLocal EnableDelayedExpansion

for /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


0

Response Number 2
Name: Dr.Gonzo
Date: July 31, 2008 at 08:43:48 Pacific
Reply:

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.


0

Response Number 3
Name: Mechanix2Go
Date: July 31, 2008 at 08:48:35 Pacific
Reply:

remove the ECH which preceeds the MOVE.


=====================================
If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: Dr.Gonzo
Date: July 31, 2008 at 09:16:05 Pacific
Reply:

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.


0

Response Number 5
Name: Dr.Gonzo
Date: July 31, 2008 at 12:49:59 Pacific
Reply:

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)


0

Related Posts

See More



Response Number 6
Name: Mechanix2Go
Date: July 31, 2008 at 18:16:57 Pacific
Reply:

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 EnableDelayedExpansion

for /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


0

Response Number 7
Name: Dr.Gonzo
Date: August 1, 2008 at 08:45:26 Pacific
Reply:

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 EnableDelayedExpansion

for /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.


0

Response Number 8
Name: Mechanix2Go
Date: August 2, 2008 at 01:29:41 Pacific
Reply:

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


0

Response Number 9
Name: Mechanix2Go
Date: August 2, 2008 at 07:21:19 Pacific
Reply:

Try this:

::==================================
@echo off
setLocal EnableDelayedExpansion

pushd 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


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: Need a batch file

URGENT: I need a batch file to ping www.computing.net/answers/windows-xp/urgent-i-need-a-batch-file-to-ping/146816.html

Need A batch file www.computing.net/answers/windows-xp/need-a-batch-file/178546.html

need help with a batch file www.computing.net/answers/windows-xp/need-help-with-a-batch-file/142147.html