0

I've started with this script for use on a Windows 98 machine.

It does what I need it to do for a specific file but I need to have this same function results with the size of the folder and it's sub-folders combined. I'm sure coding is completely different for a folder than a file but I need help.

@echo off
setlocal
set file="test.cmd"
set maxbytesize=16305780

FOR /F "usebackq" %%A IN ('%file%') DO set size=%%~zA

if %size% EQU %maxbytesize% (
    echo.Folder is the right size - PASS
) ELSE (
    echo.Folder is wrong size - FAIL
)
Stephan
  • 53,940
  • 10
  • 58
  • 91
  • A directory doesn't have a size, what you need is the total combined size of the files within a directory. – Compo Jun 27 '19 at 20:03
  • 2
    I'm quite sure, Windows 98 doesn't have `for /f` or `%~` modifiers – Stephan Jun 27 '19 at 20:04
  • 1
    Yes, @Stephan, everything that relies on Command Extensions (which have been introduced in Windows NT) is for sure not supported by `command.com`; maybe the script has been developed on another machine than the target... – aschipfl Jun 27 '19 at 22:11
  • What you can do to get the total size of the contents of a directory is to capture the next-to-last line of the output of `dir /S /W /-C`, which contains something like `#### File(s) ####### bytes` (regard that this text is locale-dependent!)... – aschipfl Jun 27 '19 at 22:18
  • yes - `command.com` is *very* basic compared to `cmd.exe`. I strongly suggest switching to QBASIC (completely or just for the parts that can't be done with DOS), which is part of DOS (and so also of WIN95/98) – Stephan Jun 28 '19 at 08:20
  • @Compo, this is true. I wasn't thinking of it in this way. aschipfl, you are also correct. I started this script on a Windows 7 Ent. machine. I'm sort of creeping along seeing what works and what doesn't as I go. I've made numerous changes between the 2 OS's to get any type of output. On a side note, I don't fully understand the rest of the discussion so far. I'm pretty green. – ccomito1223 Jun 28 '19 at 13:25
  • @ccomito1223 DOS is based on command.com, the Windows command line is based on `cmd.exe`, which introduced Command extensions (in other words: they boosted the commands to do much more than before). Commands are backward compatible, meaning old DOS scripts continue to work in `cmd`, but it's almost impossible to get scripts of the more modern `cmd` running in DOS (unless they are designed accordingly - meaning not using any of the extensions). ... – Stephan Jun 28 '19 at 15:51
  • ... On a Windows command prompt show the help of a command (like `for /?`. Most of the commands have a line "If Command Extensions are enabled..." (mostly quite at the beginning). All below that line doesn't work in DOS. (the command prompt in WIN98 is `DOS`) – Stephan Jun 28 '19 at 15:51

0 Answers0