Jump to content

Looking For A Command Line Util


Recommended Posts

Posted

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 drive

The 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 :)


Posted

how about giving this a try...

for /f "tokens=3 delims=) " %i IN ('dir ^| find "bytes free"') DO ECHO %i

Remember, if you are using it in a batch file you will need to change the %i to %%i

Do you need the commas removed?

Posted

Or better yet...

for /f "tokens=3 delims=) " %%i IN ('c:\ dir ^| find "bytes free"') DO SET freespace=%%i
for /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%m

Then just call the variable %freespace% and it will be the number of bytes without commas

Posted

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 :)

Posted

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=%%i
for /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%m

Posted
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=%%i
for /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%m

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\" /s

it 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 :D

post-36735-1109616251_thumb.jpg

Posted

set checkpath=C:\recorded tvs\
for /f "tokens=3 delims=) " %%i IN ('dir %checkpath% ^| find "bytes free"') DO SET freespace=%%i
for /f "tokens=1-5" %%i IN ('echo %freespace%') DO set freespace=%%i%%j%%k%%l%%m

That should do the trick for you

Posted

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=%%i
for /f "tokens=1-5" %%i IN ('echo %usedspace%') DO set usedspace=%%i%%j%%k%%l%%m

nope 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"?

Posted
set checkpath=C:\recorded tvs\

for /f "tokens=4 delims=) " %%i IN ('dir %checkpath% ^| find "bytes" ^| find /n "free"') DO SET usedspace=%%i

for /f "tokens=1-5" %%i IN ('echo %usedspace%') DO set usedspace=%%i%%j%%k%%l%%m

notice the edition in red. That should do the trick

Posted

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"

Posted

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 :)

Posted

OK. here. Ignore all else. I made a mistake. it's /v not /n

set checkpath=C:\recorded tvs\
for /f "tokens=3 delims=) " %%i IN ('dir %checkpath% ^| find "bytes" ^| find /v "free"') DO SET usedspace=%%i
for /f "tokens=1-5" %%i IN ('echo %usedspace%') DO set usedspace=%%i%%j%%k%%l%%m

I also changed the tokens back to 3, not 4... if you don't make that change you will get "bytes" back

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...