# Solved: Namning Issues with .bat/.vbs script



## notthisyear (Jan 7, 2009)

Hi,

I need some help.

I have a .vbs script that gathers information about the diskquota settings (I use Windows Server 2008). Then I let a .bat script save the information in a .txt file. Now, the problem (among others...) is naming the .txt. When the script creates the file, I want the current time to be its name. Right now, that doesn't happen.

I´ve tried these variations:


```
@echo off
set clock = %TIME%
CSCRIPT.EXE report.vbs > %clock%.txt
```
and


```
@echo off
CSCRIPT.EXE report.vbs > %TIME%.txt
```
Neither works... =/

Thankful for any kind of assistance!

/notthisyear


----------



## StumpedTechy (Jul 7, 2004)

I think your going to have problems using those because of the special charater limitations on the file system remember you cannot use :'s and /'s.

Are there times your not using the pipe to an output file for this report.vbs? If not why not add something like this to your VBS?

strDate = Replace(Date,"/","-")
strTime = Replace(Time,":","-")
OUTPUT_FILE_NAME = "Filename created on "&strDate&" @ "&strTime&".csv"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFileOutput = objFSO.CreateTextFile(OUTPUT_FILE_NAME)


----------



## notthisyear (Jan 7, 2009)

At first, thanka for the reply! 


```
strDate = Replace(Date,"/","-")
strTime = Replace(Time,":","-")
OUTPUT_FILE_NAME = ""&strDate&" @ "&strTime&".txt"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFileOutput = objFSO.CreateTextFile(OUTPUT_FILE_NAME)
```
As you can see I did a slight modification; I changed the OUTPUT_FILE_NAME file extension to .txt instead of .csv (acually I have no idea of what kind of file a .csv is...). I did that because I want to have all the information in a .txt file. But then the script created a textfile (with the correct name!  If there´s a possibility to change the time format to 24 h ( I´m from Sweden) that would be great) that was empty... So probably I did something wrong...

The reason for wanting the .txt file is that I want to have it mailed to the network admin. Probably you can integrate the mail function in the actual .vbs script. Problem is, I´m not very experienced in scripting (this is a school project). That´s why I wanted to do the different functions (that will say generating the report, save it in a .txt (with the correct name) and then mailing the .txt) in pieces.

Maybe it´s a lot to ask, but perhaps someone might know where to find a guide on these things. Or, in the best scenario, this isn´t so difficult. But, since I don´t know very much myself, I turned to tech support... 

Regards,
notthisyear


----------



## StumpedTechy (Jul 7, 2004)

csv is comma seperated value this file works well if your doing things like -

PC1 - value 1, value 2, value 3
PC2 - value 1, value 2, value 3

What this allows you to do is open it in excel and then use things like sort and a bunch of other things that REALLY make the data more readable than a common text file.

txt is fine though CSV and TXT are both just plain text information so either or is no difference except viewing formatting.

If you need 24 hour time you would want to do something like

Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime")
for Each objItem in colItems
strTime = objItem.Hour & "-" & objItem.Minute & "-" & objItem.Second

This then would give you 24 hour time.

What you have done wrong is you put this in the VBS but before your VBS was parsing out to a batch file. What you now need to do is look at the VBS and see where its getting output and make sure all output is now going to objFileOutput.WriteLine

E.G.

You have it like this -
strDate = Replace(Date,"/","-")
strTime = Replace(Time,":","-")
OUTPUT_FILE_NAME = ""&strDate&" @ "&strTime&".txt"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFileOutput = objFSO.CreateTextFile(OUTPUT_FILE_NAME)
Insert your code that is doing checks
objFileOutput.WriteLine information from tthe code above

so in other words something like this -

strDate = Replace(Date,"/","-")
strTime = Replace(Time,":","-")
OUTPUT_FILE_NAME = ""&strDate&" @ "&strTime&".txt"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFileOutput = objFSO.CreateTextFile(OUTPUT_FILE_NAME)
Set objWMIService = GetObject("winmgmts:\\My-PC\root\cimv2")
If Err.Number <>0 Then
objFileOutput.WriteLine "My-PC, Unable to access WMI check WMI functionality on this computer."
Else
objFileOutput.WriteLine "My-PC, WMI is online."

(this is fudged code to give you an idea I took out alot of variables so this may not work if you just copy it)


----------



## TheOutcaste (Aug 8, 2007)

Welcome to TSG!


notthisyear said:


> ```
> @echo off
> set clock = %TIME%
> CSCRIPT.EXE report.vbs > %clock%.txt
> ```


Does the time variable output the time in the format you want, but just has the : character?
If so, you can replace the *:* with a *-* (or anything else) real easy by adding one line:


```
@echo off
set clock=%TIME%
[B]set clock=%clock:[COLOR=Red]:[/COLOR]=[COLOR=DarkOrchid]-[/COLOR]%[/B]
CSCRIPT.EXE report.vbs > %clock%.txt
```
string1 will be replaced by string2
My system also shows hundredths of a second:
15:54:11.06
That can be removed with one more line:
*set clock=%clock:~0,-3%*
This will remove the .06 part, leaving just 15:54:11
Set *Set /?* for info. It's in the section right after the description of the /P switch.

All assuming you still want to redirect the output in the batch file rather than doing it all in the vbs script.

The builtin help */?* (and */?:full* for some commands) has a lot of info on the command line commands.

Some useful sites (mainly batch but a couple of script links):
DOS and VB Scripting Links
Command-line reference A-Z
Using batch parameters
Windows 95/98/ME Batch file Tutorial (Still a good basic reference for WinNT/2K/XP)
Batch File Functions for NT4/2000/XP/2003
Rob van der Woude's Scripting Pages
Microsoft Script Center
Beginners Guides: WindowsXP Command Prompt
Beginners Guides: Understanding and Creating Batch Files

HTH

Jerry


----------



## notthisyear (Jan 7, 2009)

Thank you guys! 

When I use the method of redirecting the output file in a batch program, it works perfectly! When I tried to have it all in a .vbs script, I encountered several problems... Sadly, I don´t have very much time left, so I´m probably going to do the different parts seperatly. It seems to be a lot easier than creating a .vbs script that does the whole thing. (Even if a single .vbs script looks more professional, which might lead to a higher grade... ) 

But still, I have one little issue left. I want the .txt to be mailed to the system admin. Is this very difficult to do? 

Thanks for your time!

/notthisyear


----------

