Solved

check if file exist if not make one

Posted on 2010-11-16
9
615 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

Technology Partners: 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!

Question has a verified solution.

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

Can I legally transfer my OEM version of Windows to another PC?  (AKA - Can I put a new systemboard in my OEM PC?) Few of us are both IT and legal experts but we all have our own views of Microsoft's licensing rules and how they apply.  There are…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

617 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