Solved

check if file exist if not make one

Posted on 2010-11-16
9
613 Views
Last Modified: 2012-06-21
I need a vb script that can do the following steps please
1- check if a text file (an empty one) called Install.txt exist under %appdata%\org
2- if the file exist do nothing
3- If the the text file does not exist, create one under %appdata%\load\org then launch another vb script called load.vbs from C:\temp\

This where I got so far:

Dim sUserName
Dim sFileName
Dim sFile
Dim strFolder, objFSO
Set objWShell=CreateObject("Wscript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
susrName=objWShell.expandEnvironmentStrings("%USERNAME%")
strFolder="C:\Documents and Settings\"&susrName&"\Application Data\load\Org"
sFileName=(strFolder & "\" & "Install.txt")
Set sFile=objFSO.CreateTextFile(sFileName, True)
Set objFSO=nothing
Set objShell=nothing
Set sFile=nothing

Thank you
0
Comment
Question by:JAWC
  • 7
  • 2
9 Comments
 
LVL 27

Expert Comment

by:KenMcF
ID: 34144646

You can try something like this

Dim sUserName
Dim sFileName
Dim sFile
Dim strFolder, objFSO
Set objWShell=CreateObject("Wscript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
susrName=objWShell.expandEnvironmentStrings("%USERNAME%")
strFolder="C:\Documents and Settings\"&susrName&"\Application Data\load\Org"
sFileName=(strFolder & "\" & "Install.txt")
If objFSO.FileExists(sFileName) Then
Wscript.quit
Else
Set sFile=objFSO.CreateTextFile(sFileName, True)
Set objFSO=nothing
Set objShell=nothing
Set sFile=nothing
End if


0
 

Author Comment

by:JAWC
ID: 34144671
Thank you Ken, This is good but I will have to launch a vbscript after creating the text file

3- If the the text file does not exist, create one under %appdata%\load\org then launch another vb script called load.vbs from C:\temp\




0
 

Accepted Solution

by:
JAWC earned 0 total points
ID: 34144882
I managed to make the script to work by doing the following

Dim sUserName
Dim sFileName
Dim sFile
Dim strFolder, objFSO
set WshShell = WScript.CreateObject("WScript.Shell" )
Set objWShell=CreateObject("Wscript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
susrName=objWShell.expandEnvironmentStrings("%USERNAME%")
strFolder="C:\Documents and Settings\"&susrName&"\Application Data\load\Org"
sFileName=(strFolder & "\" & "Install.txt")
If objFSO.FileExists(sFileName) Then
Wscript.quit
Else
Set sFile=objFSO.CreateTextFile(sFileName, True)
wshshell.Run """C:\temp\load.vbs"""
Set objFSO=nothing
Set objShell=nothing
Set sFile=nothing
End if

Thank you Ken for trying
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:KenMcF
ID: 34153784
"I managed to sort the issue out", you used my solution your main issues of checking to see if the file exists and create on if it does not. The only thing I forgot to put in my post was to call the other vbs.
0
 

Author Comment

by:JAWC
ID: 34153873
Hi Ken.
If you look at my question I did add my own script:
Dim sUserName
Dim sFileName
Dim sFile
Dim strFolder, objFSO
Set objWShell=CreateObject("Wscript.Shell")
Set objFSO=CreateObject("Scripting.FileSystemObject")
susrName=objWShell.expandEnvironmentStrings("%USERNAME%")
strFolder="C:\Documents and Settings\"&susrName&"\Application Data\load\Org"
sFileName=(strFolder & "\" & "Install.txt")
Set sFile=objFSO.CreateTextFile(sFileName, True)
Set objFSO=nothing
Set objShell=nothing
Set sFile=nothing

Your script had the following line s add it to it:
If objFSO.FileExists(sFileName) Then
Wscript.quit
Else
Set sFile=objFSO.CreateTextFile(sFileName, True)

Which it was very much appreciated. I can not guess that you have forgotten to add the laucnh of the VB script.

Only because it is not worth arguing about things like this and I do appreciate you time and your assistance. I will give you the point even though it is too much for three lines.

Again thank you for your help.
0
 

Author Comment

by:JAWC
ID: 34153906
Sorry I closed it with granting Ken points. please let me know how to do this . IDear Moderator could you sort this one out.

Thank you
0
 

Author Comment

by:JAWC
ID: 34154218
Ken: I will make sure that you get the points. please take note of my earlier explaination
17/11/10 03:02 AM, ID: 3415387

Regards
0
 

Author Comment

by:JAWC
ID: 34171935
Dear moderator please Grant ken the rewards point.

Thank you
0
 

Author Closing Comment

by:JAWC
ID: 34186317
I have accepted my solution because I did comlete the script that I was looking for.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We have adopted the strategy to use Computers in Student Labs as the bulletin boards. The same target can be achieved by using a Login Notice feature in Group policy but it’s not as attractive as graphical wallpapers with message which grabs the att…
Step by step guide to Clean and Sort your windows registry! Introduction: Always remember: A Clean registry = Better performance = Save your invaluable time In this article we're going to clear our registry manually! Yes, manually! The e…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question