Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

check if file exist if not make one

Posted on 2010-11-16
9
Medium Priority
?
619 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
Screencast - Getting to Know the Pipeline
Suggested Courses

926 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