Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: File Properties using batch  (Read 2208 times)

0 Members and 1 Guest are viewing this topic.

B3ni

  • Guest
File Properties using batch
« on: September 11, 2006, 07:12:47 AM »
anyone know how i can use a batch file to look up the size\free space on a drive??

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: File Properties using batch
« Reply #1 on: September 11, 2006, 07:31:03 AM »
Since I have to guess your OS, you have to guess if this will work for you:

Code: [Select]
@echo off
for /f "tokens=3" %%i in ('dir [highlight]c:[/highlight] ^| find /i "free"') do echo %%i

Feel free to change the drive letter.

 8-)
« Last Edit: September 11, 2006, 07:32:05 AM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

B3ni

  • Guest
Re: File Properties using batch
« Reply #2 on: September 11, 2006, 07:36:44 AM »
thanks for responding siderwinder, i need to do it both on nt4 and xp, many thanks

soSagtDieHex

  • Guest
Re: File Properties using batch
« Reply #3 on: September 16, 2006, 11:40:29 AM »
Quote
Code: [Select]
@echo off
for /f "tokens=3" %%i in ('dir c: ^| find /i "free"') do echo %%i


it works for me (Windows XP) but only if I write
for /f "tokens=3" %i in ('dir c: | find /i "free"') do echo %i

dir c: | find etc. is good
dir c: ^| find etc. isn't
what's with the "^|" syntax ?  :-?

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: File Properties using batch
« Reply #4 on: September 16, 2006, 02:50:57 PM »
The caret (^) acts as a escape character when using DOS special characters. I couldn't find much documentation on why you need it, just that without it under certain conditons the parser will error out.

Apparently you need to use it when a DOS special symbol is used in a nested command. ::)

In the example I gave you: for /f "tokens=3" %%i in ('dir c: ^| find /i "free"') do echo %%i, the pipe (|) is embedded in the FOR command.

I know, I know, not much of a response, but use it if you get an error by not using it. ;D
« Last Edit: September 16, 2006, 02:51:34 PM by Sidewinder »
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

soSagtDieHex

  • Guest
Re: File Properties using batch
« Reply #5 on: September 16, 2006, 05:23:34 PM »
Quote
The caret (^) acts as a escape character when using DOS special characters.
Apparently you need to use it when a DOS special symbol is used in a nested command. ::)


I guess this shows why an expert is called an expert  [smiley=thumbsup.gif]

It's exactly as you said.
In a batch file, if I leave the ^ out it breaks, if it's in, the parser itself will take care of it,
just the opposite at the command line.
A bit like doubling % in batch isn't it
I never had any idea it should work this way. Thanks a lot for the info  [smiley=vrolijk_26.gif]  [smiley=beer.gif]
« Last Edit: September 16, 2006, 05:25:48 PM by soSagtDieHex »