Specialty Forums
Security and Virus
General Hardware
CPUs/Overclocking
Networking
Digital Photo/Video
Office Software
PC Gaming
Console Gaming
Programming
Database
Web Development
Digital Home

General Forums
Windows XP
Windows Vista
Windows 95/98
Windows Me
Windows NT
Windows 2000
Win Server 2008
Win Server 2003
Windows 3.1
Linux
PDAs
BeOS
Novell Netware
OpenVMS
Solaris
Disk Op. System
Unix
Mac
OS/2

Drivers
Driver Scan
Driver Forum

Software
Automatic Updates

BIOS Updates

My Computing.Net

Solution Center

Free IT eBook

Howtos

Site Search

Message Find

RSS Feeds

Install Guides

Data Recovery

About

Home
Reply to Message Icon Go to Main Page Icon

Batch to check folder size

Original Message
Name: ld123
Date: February 1, 2008 at 00:21:46 Pacific
Subject: Batch to check folder size
OS: XP SP2
CPU/Ram: 2gb
Model/Manufacturer: HP Pav dv6000
Comment:
I am hoping someone can help with this. I have three bat files. The first is set to run with a scheduler, and it calls the second and third bat file. What I would like is to poll a certain folder every 60 seconds, and if it is empty, then call the first bat. Once the first bat runs, it will call the 2nd and 3rd, then the poller will start again after they complete.

If there is something still in the folder, have the "poller" sleep for 60 seconds, then poll again until it is empty. Thanks in advance.

When in doubt, format.


Report Offensive Message For Removal


Response Number 1
Name: Mechanix2Go
Date: February 1, 2008 at 05:13:50 Pacific
Subject: Batch to check folder size
Reply: (edit)
::== poll.bat
@echo off
setLocal EnableDelayedExpansion

pushd c:\test

:loop

dir/a-d/b > nul 2>nul

if errorlevel 1 (
echo call 1
echo call 2
echo call 3
)

ping -n 1 -w 60000 1.1.1.1 > nul
goto :loop



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

M2



Report Offensive Follow Up For Removal

Response Number 2
Name: ld123
Date: February 1, 2008 at 08:56:44 Pacific
Subject: Batch to check folder size
Reply: (edit)
Thank you for the response. I'll check this out and let you know the results.

When in doubt, format.


Report Offensive Follow Up For Removal

Response Number 3
Name: ld123
Date: February 1, 2008 at 10:34:13 Pacific
Subject: Batch to check folder size
Reply: (edit)
Ok, if you can't tell, I'm a little new to this. It looks like it's doing exactly what I need. Here is the batch with edits to work in my environment:

@echo off

:loop
dir/a-d/b c:\staging> nul 2>nul
if errorlevel 1 (
call c:\ami\bin\first.bat
)
TIMEOUT /T 5 /NOBREAK
goto :loop

2 questions, first, if I wanted to reverse this and run a batch when it sees new folders, would I set the errorlevel to 0?

Second, how would I set the batch above to quit and exit after it runs the called batch file? Meaning, the batch will poll a folder to see when it is empty. Once it sees that it is empty, it will call the first.bat, run it, and then stop and exit all together.

Oh, thank you again.

When in doubt, format.


Report Offensive Follow Up For Removal

Response Number 4
Name: Mechanix2Go
Date: February 1, 2008 at 16:58:00 Pacific
Subject: Batch to check folder size
Reply: (edit)
You seem to catch on quick.

"if I wanted to reverse this and run a batch when it sees new folders, would I set the errorlevel to 0?"

No. This is a classic gotcha. A test for errorlevel means:

if errorlevel X [OR MORE] !]

so 0 will always be true. To reverse the logic, use:

if not errorlevel 1

"the batch will poll a folder to see when it is empty. Once it sees that it is empty, it will call the first.bat, run it, and then stop and exit all together."

Simplest way is not CALL but just run the next bat. That way it never returns. Like this:

::==
@echo off

:loop
dir/a-d/b c:\staging> nul 2>nul
if errorlevel 1 (
c:\ami\bin\first.bat
)
TIMEOUT /T 5 /NOBREAK
goto :loop
::==


::==



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

M2



Report Offensive Follow Up For Removal

Response Number 5
Name: ld123
Date: February 2, 2008 at 19:36:21 Pacific
Subject: Batch to check folder size
Reply: (edit)
Let me be the first to say, you the man. This works perfectly. Can you recommend a good reference site? I know the help command, but just looking at the set /? output hurts my brain.

Oh, almost forgot. If I open a window from the command line, "start c:\folder", is there a way to close it via command line? If not, no biggie.
When in doubt, format.


Report Offensive Follow Up For Removal


Response Number 6
Name: Mechanix2Go
Date: February 3, 2008 at 00:20:16 Pacific
Subject: Batch to check folder size
Reply: (edit)
"is there a way to close it via command line?"

Not that I know of.


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

M2



Report Offensive Follow Up For Removal



Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Batch to check folder size

Comments:

 
  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 


Data Recovery Software




how to setup call of duty to joytok

WindowsME / HotMail Problem

Corrupt memory

Convert fat32 to Ntfs

Best WinMo phone of 2008


The information on Computing.Net is the opinions of its users. Such opinions may not be accurate and they are to be used at your own risk. Computing.Net cannot verify the validity of the statements made on this site. Computing.Net and Computing.Net, LLC hereby disclaim all responsibility and liability for the content of Computing.Net and its accuracy.
PLEASE READ THE FULL DISCLAIMER AND LEGAL TERMS BY CLICKING HERE

All content ©1996-2007 Computing.Net, LLC