Make For /F loop read in null tokens

October 6, 2010 at 06:59:30
Specs: Windows XP
I'm writing in Batch a little script that will read through an extract from an Active Directory users query. The purpose of this is using the w32tm /ntte to turn the AD FileTime into something that can be read and putting it back into the same comma delimited format that I got it out of. I would do it one at a time but I have 40,000 of them that need to be done on a regular basis. I've got everything working, except that occasionally (such as if they have never logged on) a field will be completely blank. This means that the token is null and so %%A skips all the nulls and goes until the next non null item, which throws off the rest of my script. Is there any way to get around this? Something either to replace a null token as it comes in with a zero or a space or something?

My FOR looks as follows:

FOR /F "tokens=* delims=, skip=1" %%A IN (userstest.txt) DO (CALL :append %%A)

Thanks.


See More: Make For /F loop read in null tokens

Report •


#1
October 7, 2010 at 06:48:45
Off the top of my head, I have two options:
1) Read the line with "delims=" to get the entire raw line, then replace ",," with something like ", ," and parse the modified line with that FOR statement.

2) Use a different language. VBScript would be my choice, but that's more personal preference than anything.

How To Ask Questions The Smart Way


Report •

#2
October 8, 2010 at 07:57:18
I did swap over to vbscript which makes it much more dynamic and able to handle all of that stuff. Now my problem is that you can't hide wscript.exec and you can't get output from wscript.run without writing it to a text file and reading it back. I want it to be as efficient as possible since the command in the cmd line will have to be ran 80,000 times.

Report •

#3
October 8, 2010 at 12:35:31
What are you doing with WScript.Shell.Run/.Exec? If you're running w32tm, you should probably look into using SWbemDateTime for time/date conversion.
Const someFileTime = "129311982630000000" 'Oct 10, 2010-ish
Set dateTime = CreateObject("WbemScripting.SWbemDateTime")
dateTime.SetFileTime someFileTime, False 'Assumed: FileTime is not localized.
WScript.Echo someFileTime & " -> " & dateTime.GetVarDate

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
October 8, 2010 at 13:07:51
Razor you are my new favorite person.

Report •


Ask Question