Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4098982
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:22:26+00:00 2026-05-20T20:22:26+00:00

update SOLVED – the problem is not with my code. there is a design

  • 0

update SOLVED – the problem is not with my code. there is a design limitation (some might say “bug”) in the command processor. the IF comparison operators do not work with values higher than 2147483648. now I just have to figure out how to strip off some of the least significant digits for the workaround. thanks to all for reading.

=======

hello out there in cyberland,

I manage a small company’s network. I’m trying to set up an automated archival process using a batch file running on a server, and need a little help with the logic. I’m not a programmer and don’t have the time to learn PowerShell or VBscript. I have read and re-read the MS command reference on IF, FOR, and CALL, and can not figure out what I’m doing wrong.

We have a Windows 2000 Server with two disk drives and a tape drive. One disk has a shared folder, call it Public; the other disk is not shared, call it Staging.

The Public drive will accept incoming backups from the client desktops. I need the process to move files from the Public drive to the Staging drive until the drive is too full to accept any more files, whereupon the tape backup starts. Upon completion of the tape run, the Staging drive will be emptied and the process will resume moving files from Public to Staging.

The goal is to automatically and perpetually archive the desktop backup files to tape, with no user intervention other than changing the tape.

You may ask, why involve two drives? Two reasons:

1) If the desktops back up directly to the Staging drive, at some point the client desktop backups will fail for lack of space on the target drive. I have no way to predict when this will occur; the only definable condition I can think of would be an arbitrary threshold of free disk space, but since the backup files to be archived will be different sizes, I could run into a situation where the target drive free space is above the threshold, but the next backup exceeds that space. Result: client desktop backup fails and server tape backup does not start.

2) If the Staging drive fills up and the tape backup fails for some reason (tape not changed or whatever), having the desktops back up to the Public drive buys me some time to fix the tape issue before the desktop backups begin to fail.

Here is the algorithm I’m trying to code:

1) Begin

2) Obtain free space on Staging drive

3) Obtain size of smallest file on Public drive (if no files present, exit)

4) Compare file size with free space on Staging drive

5) if file will fit, move it to Staging drive; else, exit and start Tape Backup

6) return to Begin

And here is my batch code which is not working. At this stage in testing, I have one file (8 GB) in the Public drive which will fit in the free space (32 GB) on the Staging drive. The set command confirms the variables are being set as expected; the process is failing at the statement [ if %BKFsize% LSS %DiskFree%” ]. Instead of the file being moved, the tape routine specified by ‘else’ is called instead:

@echo off
setlocal enableextensions enabledelayedexpansion
:Begin
REM   obtain and display free space on Staging drive.
D:
for /f "tokens=3 delims= " %%A in ('dir ^| find "bytes free"') do (
set Z=%%A
set Z=!Z:,=!
)
set DiskFree=!Z!
echo.
echo D: has %DiskFree% bytes free
echo.
REM   obtain sizes of files on Public drive to be moved.
E:
cd \backup.email
if not exist *.bkf exit
dir *.bkf /b /os > BKFlist.txt
for /f "tokens=*" %%G in (BKFlist.txt) do call :CheckBKF "%%G"
goto :eof
:CheckBKF
set BKFfile=%1
set BKFsize=%~z1
echo.
echo File %BKFfile% is %BKFsize% bytes
echo.
set
pause
REM   move file(s) to Staging drive, space permitting; or, 
REM   if not enough space for smallest file, start tape backup.
if %BKFsize% LSS %DiskFree% (
echo Moving file %BKFfile% to drive D
echo.
move E:\backup.email\%BKFfile% D:\backup.email
) else (
C:\WINNT\AutoBackup\TapeBKF.cmd
exit
)
goto Begin
:End

I know this must be fairly simple but like I said, I’m not a programmer, and I bow to your superior skill. Any advice is much appreciated, and thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:22:27+00:00Added an answer on May 20, 2026 at 8:22 pm

    In batch file, there is no real difference between strings and integers types, but that isn’t your problem here.

    The problem is that integers only works in the 32 bit signed range.
    -2147483648 to 2147483647

    But your filesize is greater and also your disk space.
    To test this you could try to add a one.

    Set /a myvar=BKFsize+1
    Set /a myvar=DiskFree+1
    

    I suppose you get an error.

    You could solve it, if you try to use the string compare, currently you do a string compare but your numbers are not of the same length, so you get “unpredictable” results.
    But if you adjust/filling the strings with zeros so they have the same length, it should work.

    set "strBKSize=000000000000000000%bkSize%"
    set "strBKSize=%strBKSize:~-15%"
    set "strDisksize=000000000000000000%Disksize%"
    set "strDisksize=%strDisksize:~-15%"
    

    Or you try to calculate not with bytes, but in MB or GB, by removing 6 or 9 numbers/characters.

    set BKFsizeGB=%BKFsize:~0,-9%
    

    Then you can use them as numbers.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Updated Problem solved, I have some design problem here. The directory looks like that:
Update 7/17 SOLVED I've updated my code to the Solved version. Original Question I'm
UPDATE: First problem solved, second one described at the bottom of this post. UPDATE2:
Update II Problem Solved but Why? This has been the biggest headache ever. My
UPDATE The issue is solved, all the code you can see works. Hello! I
[Update] Unfortunately I never had an opportunity to solve this problem. However, there are
The problem is not solved although I accepted one answer. Problem: Vim updates very
[Update] Solved the Problem by generating a new web.config. Possible error was the second
UPDATE: SOLVED!!! Please see the answer I added below Does anyone know if there
Update: Solved, with code I got it working, see my answer below for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.