February 28, 200521 yr Hi ive googled this, but only come up with freedisk which is for windows 2000.Im looking for a console util which i can run to see if free space is left on the driveThe reason for this is someone has asked for a script which moves files according to thier drives states, and i fancy trying to help whilst trying to learn more about cmd.exe
February 28, 200521 yr how about giving this a try...for /f "tokens=3 delims=) " %i IN ('dir ^| find "bytes free"') DO ECHO %iRemember, if you are using it in a batch file you will need to change the %i to %%iDo you need the commas removed?
February 28, 200521 yr Or better yet...for /f "tokens=3 delims=) " %%i IN ('c:\ dir ^| find "bytes free"') DO SET freespace=%%ifor /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%mThen just call the variable %freespace% and it will be the number of bytes without commas
February 28, 200521 yr Author Hi mate i tried to run the later script you gave from a .cmd file but got 'c:\' is not recognized as an internal or external command,operable program or batch file. Many thanks though
February 28, 200521 yr HAHA... try switching that around. I typed it wrong. dir c:\ (or use place the driver letter you want)for /f "tokens=3 delims=) " %%i IN ('dir c:\ ^| find "bytes free"') DO SET freespace=%%ifor /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%m
February 28, 200521 yr Alternately, you could try the PSInfo utility from Sysinternals:http://www.sysinternals.com/ntw2k/freeware/psinfo.shtml - Ravashaak
February 28, 200521 yr Author HAHA... try switching that around. I typed it wrong. dir c:\ (or use place the driver letter you want)for /f "tokens=3 delims=) " %%i IN ('dir c:\ ^| find "bytes free"') DO SET freespace=%%ifor /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%m<{POST_SNAPBACK}>Thanks un4given1, very kind of you.Im trying to help someone, and ive got some basic stuff working but kind of ran into a problem.So far im checking each drive to see if it has at least 1GB of space free, now this is a problem if the TV progs he has recorded using his tv card adds up to more than 1GB of data.So i was thinking i need to create a variable to read how many files he has in C:\recorded tvs\.Now i know if I run DIR "C:\recorded tvs\" /sit does give me a value of the total byte size that the files add up to in C:\recorded tvs and all its sub directories, i just dont know how to get that information! into a variable Then i can just check if the drive has at least the space that C:\recorded has, if not check the next disk and copy them there, or go onto the next disk etc.Thanks yet again, also could you use some comment tags or someething to explain whats happening. Like i said i want to learn
February 28, 200521 yr set checkpath=C:\recorded tvs\for /f "tokens=3 delims=) " %%i IN ('dir %checkpath% ^| find "bytes free"') DO SET freespace=%%ifor /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%mThat should do the trick for you
February 28, 200521 yr Author Thanks again, really appreciate your help here, obviously i will be linking to the thread to give full credit where is due.but, for C:\recorded tvs, i need to find the used space this time, not the free space, so would it be:set checkpath=C:\recorded tvs\for /f "tokens=3 delims=) " %%i IN ('dir %checkpath% ^| find "bytes"') DO SET usedspace=%%ifor /f "tokens=1-5" %%i IN ('echo %usedspace%') DO set usedspace=%%i%%j%%k%%l%%mnope that didnt do what i needed, it still shown the free bytes, is that because bytes is global and used in both:"free bytes" and "bytes"?
February 28, 200521 yr set checkpath=C:\recorded tvs\for /f "tokens=4 delims=) " %%i IN ('dir %checkpath% ^| find "bytes" ^| find /n "free"') DO SET usedspace=%%ifor /f "tokens=1-5" %%i IN ('echo %usedspace%') DO set usedspace=%%i%%j%%k%%l%%mnotice the edition in red. That should do the trick
February 28, 200521 yr If you use only the search string of "bytes" it will return 2 lines and run the FOR statement on each line. That's why I added the second find string to remove the line including "free"
February 28, 200521 yr Author bah didnt work its still returning the free drive space , so i guess this is the end of the road?Many thank again anyway m8
February 28, 200521 yr No... it should be returning the space used. make sure you have the /n on the second find string.
February 28, 200521 yr OK. here. Ignore all else. I made a mistake. it's /v not /nset checkpath=C:\recorded tvs\for /f "tokens=3 delims=) " %%i IN ('dir %checkpath% ^| find "bytes" ^| find /v "free"') DO SET usedspace=%%ifor /f "tokens=1-5" %%i IN ('echo %usedspace%') DO set usedspace=%%i%%j%%k%%l%%mI also changed the tokens back to 3, not 4... if you don't make that change you will get "bytes" back
February 28, 200521 yr Author Great! it worked but only after I added /S after %checkpath% to check for subdirectories, thanks mate your a star!
Create an account or sign in to comment