Solved

check if file exist if not make one

Posted on 2010-11-16
9
611 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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

772 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