Page 1 of 1

Batch format convert

Posted: 19 Aug 2010 04:19
by karzer
I have used a batch, but the program does not support this use case, I wonder how we can convert vbs format?

Code: Select all

@echo off
cscript quota.vbs //nologo >quota.txt
FOR /F "delims=, tokens=2" %%G IN (quota.txt) DO @echo %%G | findstr User


Thank you very much

quota.vbs

Code: Select all

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
strDrive = "Win32_LogicalDisk.DeviceID=" & chr(34) & "F:" & chr(34)


Set colQuotas = objWMIService.ExecQuery _
    ("Select * from Win32_DiskQuota Where Status = 2")


For Each objQuota in colQuotas
    Wscript.Echo "User: "& objQuota.User     
    'Wscript.Echo "Disk Space Used: "& objQuota.DiskSpaceUsed

Next



quota.txt

Code: Select all

User: Win32_Account.Domain="srv",Name="User456"
User: Win32_Account.Domain="srv",Name="User369"
User: Win32_Account.Domain="srv",Name="User789"
User: Win32_Account.Domain="srv",Name="User987"

Re: Batch format convert

Posted: 19 Aug 2010 04:31
by orange_batch
Is your problem the case-sensitivity? Where it won't show lines like Name="user789" ?

Use the /i switch.

Code: Select all

FOR /F "delims=, tokens=2" %%G IN (quota.txt) DO @echo %%G | findstr /i User


Though I recommend:

Code: Select all

FOR /F "delims=, tokens=2" %%G IN ('type quota.txt ^| findstr /i User') DO echo:%%G


Is it that you only want the value within the quotes?

Code: Select all

setlocal enabledelayedexpansion

FOR /F "delims=, tokens=2" %%G IN ('type quota.txt ^| findstr /i User') DO (
set myvar=%%G
set "myvar=!myvar:~6,-1!"
echo !myvar!
)


If you want DOS to catalog the values into variables... should work...

Code: Select all

setlocal enabledelayedexpansion

FOR /F "delims=, tokens=2" %%G IN ('type quota.txt ^| findstr /i User') DO (
set /a counter+=1
set line!counter!=%%G
call set "line!counter!=%%line!counter!:~6,-1%%"
)
:: Display catalog.
set line

:: To process catalog...
FOR /L %%X IN (1,1,!counter!) DO (
echo !line%%X!
)

Re: Batch format convert

Posted: 19 Aug 2010 04:57
by karzer
No, my problem as the first code to convert to vbs.

Re: Batch format convert

Posted: 19 Aug 2010 05:03
by orange_batch
Sorry, I don't understand what you're trying to do. Please explain.

Edit: Hold on, I see your previous topic. No offense, your English could use some work! I think this is what you want:

Replace quota.txt:

Change this format,
User: Win32_Account.Domain="srv",Name="User456"

To this format,
Name="User456"

Code: Select all

FOR /F "delims=, tokens=2" %%G IN ('"type quota.txt | findstr /i User & type nul > quota.txt"') DO echo:%%G>>quota.txt


Personally, I would syntax it this way:

Code: Select all

for /f "delims=, tokens=2" %%x in ('type quota.txt ^| find /i "User" ^& type nul >quota.txt') do echo:%%x>>quota.txt


Either way, what this does is:
1. Send each line of quota.txt into FIND.
2. FIND sends lines containing "User" to FOR loop.
3. TYPE erases quota.txt.
4. FOR finds from FIND, the text between first comma "," and third comma "," or end of line.
5. FOR loop replaces %%x with the text.
6. ECHO adds the text to quota.txt.

Re: Batch format convert

Posted: 19 Aug 2010 05:28
by karzer
Image


Code: Select all

setlocal enabledelayedexpansion

FOR /F "delims=, tokens=2" %%G IN ('type quota.txt ^| findstr /i User') DO (
set /a counter+=1
set line!counter!=%%G
call set "line!counter!=%%line!counter!:~6,-1%%"
)
:: Display catalog.
set line

:: To process catalog...
FOR /L %%X IN (1,1,!counter!) DO (
echo !line%%X!
)

Re: Batch format convert

Posted: 19 Aug 2010 05:46
by karzer

Code: Select all

@echo off
cscript quota.vbs //nologo >quota.txt
FOR /F "delims=, tokens=2" %%G IN (quota.txt) DO @echo %%G | findstr User



I just want my code to convert vbs format.
I know very little English, would benefit from the google translation page.
I apologize for my writing