Batch format convert

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
karzer
Posts: 21
Joined: 17 Jul 2010 02:56

Batch format convert

#1 Post by karzer » 19 Aug 2010 04:19

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"
Last edited by karzer on 19 Aug 2010 04:57, edited 3 times in total.

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Batch format convert

#2 Post by orange_batch » 19 Aug 2010 04:31

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!
)
Last edited by orange_batch on 19 Aug 2010 05:15, edited 2 times in total.

karzer
Posts: 21
Joined: 17 Jul 2010 02:56

Re: Batch format convert

#3 Post by karzer » 19 Aug 2010 04:57

No, my problem as the first code to convert to vbs.

orange_batch
Expert
Posts: 442
Joined: 01 Aug 2010 17:13
Location: Canadian Pacific
Contact:

Re: Batch format convert

#4 Post by orange_batch » 19 Aug 2010 05:03

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.
Last edited by orange_batch on 19 Aug 2010 05:31, edited 1 time in total.

karzer
Posts: 21
Joined: 17 Jul 2010 02:56

Re: Batch format convert

#5 Post by karzer » 19 Aug 2010 05:28

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

karzer
Posts: 21
Joined: 17 Jul 2010 02:56

Re: Batch format convert

#6 Post by karzer » 19 Aug 2010 05:46

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

Post Reply