Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Detect if file exist

Reply
 
Old 09-26-2008   #1 (permalink)
Henrique


 
 

Detect if file exist

Hi

With this code I need to erase the file if the file exists else exists
script.

But dont work Whel.

Display an error "Error in File"

ho is the problem?


If File("c:\testes\teste.ual") Then
Kill (c:\testes\teste.ual)
Else
WScript.Quit
End If



Thanks

H.S.



My System SpecsSystem Spec
Old 09-26-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Detect if file exist


"Henrique" <wq@xxxxxx> wrote in message
news:newscache$z61t7k$aq3$1@xxxxxx
Quote:

> Hi
>
> With this code I need to erase the file if the file exists else exists
> script.
>
> But dont work Whel.
>
> Display an error "Error in File"
>
> ho is the problem?
>
>
> If File("c:\testes\teste.ual") Then
> Kill (c:\testes\teste.ual)
> Else
> WScript.Quit
> End If
>
> Thanks
>
> H.S.
As far as I know there are no inbuilt functions in VB Script called "File"
or "Kill". Are these your own functions? If so then you should post them. If
not then you should look at the FileSystemObject for methods to check for
the existence of a file and how to delete a file. The downloadable help file
script56.chm will give you full details.


My System SpecsSystem Spec
Old 09-26-2008   #3 (permalink)
Henrique


 
 

Re: Detect if file exist

Hi



The VBscript for detect if the file exists is:


Set objFSO = CreateObject("Scripting.FileSystemObject")

If objFSO.fileExists("c:\testes\teste.ual") then
objFSO.DeleteFile("c:\testes\teste.ual")
Else

????????VBcript.Quit??????????????????

end if

But the Script for quit from VBScript Im finding.
You know?

Thankyou

H.S.


"Pegasus (MVP)" <I.can@xxxxxx> escreveu na mensagem
news:%23vkqF49HJHA.3548@xxxxxx
Quote:

>
> "Henrique" <wq@xxxxxx> wrote in message
> news:newscache$z61t7k$aq3$1@xxxxxx
Quote:

>> Hi
>>
>> With this code I need to erase the file if the file exists else exists
>> script.
>>
>> But dont work Whel.
>>
>> Display an error "Error in File"
>>
>> ho is the problem?
>>
>>
>> If File("c:\testes\teste.ual") Then
>> Kill (c:\testes\teste.ual)
>> Else
>> WScript.Quit
>> End If
>>
>> Thanks
>>
>> H.S.
>
> As far as I know there are no inbuilt functions in VB Script called "File"
> or "Kill". Are these your own functions? If so then you should post them.
> If not then you should look at the FileSystemObject for methods to check
> for the existence of a file and how to delete a file. The downloadable
> help file script56.chm will give you full details.
>

My System SpecsSystem Spec
Old 09-26-2008   #4 (permalink)
Pegasus \(MVP\)


 
 

Re: Detect if file exist


"Henrique" <wq@xxxxxx> wrote in message
news:newscache$c75t7k$f96$1@xxxxxx
Quote:

> Hi
>
>
>
> The VBscript for detect if the file exists is:
>
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> If objFSO.fileExists("c:\testes\teste.ual") then
> objFSO.DeleteFile("c:\testes\teste.ual")
> Else
>
> ????????VBcript.Quit??????????????????
>
> end if
>
> But the Script for quit from VBScript Im finding.
> You know?
>
> Thankyou
>
Try wscript.quit. You'll find it in script56.chm.


My System SpecsSystem Spec
Old 09-26-2008   #5 (permalink)
Henrique


 
 

Re: Detect if file exist

I hav already tested, but it gives me the error: object: "Wscript"

Now I can open the file script56.chm.


Thankyou

H.S




"Pegasus (MVP)" <I.can@xxxxxx> escreveu na mensagem
news:OaU8Hm%23HJHA.1968@xxxxxx
Quote:

>
> "Henrique" <wq@xxxxxx> wrote in message
> news:newscache$c75t7k$f96$1@xxxxxx
Quote:

>> Hi
>>
>>
>>
>> The VBscript for detect if the file exists is:
>>
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>
>> If objFSO.fileExists("c:\testes\teste.ual") then
>> objFSO.DeleteFile("c:\testes\teste.ual")
>> Else
>>
>> ????????VBcript.Quit??????????????????
>>
>> end if
>>
>> But the Script for quit from VBScript Im finding.
>> You know?
>>
>> Thankyou
>>
>
> Try wscript.quit. You'll find it in script56.chm.
>

My System SpecsSystem Spec
Old 09-26-2008   #6 (permalink)
Pegasus \(MVP\)


 
 

Re: Detect if file exist


"Henrique" <wq@xxxxxx> wrote in message
news:newscache$zf6t7k$g37$1@xxxxxx
Quote:

>I hav already tested, but it gives me the error: object: "Wscript"
>
> Now I can open the file script56.chm.
>
>
> Thankyou
>
> H.S
Let's have a look at your code!


My System SpecsSystem Spec
Old 09-26-2008   #7 (permalink)
Henrique


 
 

Re: Detect if file exist

Hi

This is my complete code:


@VBSCRIPT

DirF="c:\testes\teste.ual"

Set objFSO = CreateObject("Scripting.FileSystemObject")

If not objFSO.fileExists(DirF) then
wscript.quit
end if


adOpenStatic = 3
adLockOptimistic = 3
adUseClient = 3
Set objConnection = CreateObject("ADODB.Connection")
Set objRecordset = CreateObject("ADODB.Recordset")
StrCnn = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Supervisao\Alarmes.mdb;Persist Security Info=False"
objRecordset.CursorLocation = adUseClient
objRecordset.Open "SELECT * FROM registos" , StrCnn ,adOpenStatic,
adLockOptimistic


CRLF = Chr(13)& Chr(10)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(DirF, 1, False, -1)
DF = Split(objFile.ReadAll,CRLF)

For a = 0 to UBound(DF)

If Mid(DF(a), 72, 5) = "Alarm" Then 'Só grava se for alarme
objRecordset.AddNew
objRecordset("Data") = Mid(DF(a), 1, 12)
objRecordset("Hora") = Mid(DF(a), 13, 7) + "00"
objRecordset("Equipamento") = Mid(DF(a), 20, 5)
objRecordset("Alarme") = Mid(DF(a), 20, 41)
objRecordset.Update
End If
next

objFile.Close
objRecordset.Close

objFSO.DeleteFile(DirF)

@ENDSCRIPT




"Pegasus (MVP)" <I.can@xxxxxx> escreveu na mensagem
news:%23jzA2y%23HJHA.4884@xxxxxx
Quote:

>
> "Henrique" <wq@xxxxxx> wrote in message
> news:newscache$zf6t7k$g37$1@xxxxxx
Quote:

>>I hav already tested, but it gives me the error: object: "Wscript"
>>
>> Now I can open the file script56.chm.
>>
>>
>> Thankyou
>>
>> H.S
>
> Let's have a look at your code!
>

My System SpecsSystem Spec
Old 09-26-2008   #8 (permalink)
Pegasus \(MVP\)


 
 

Re: Detect if file exist


"Henrique" <wq@xxxxxx> wrote in message
news:newscache$te7t7k$so7$1@xxxxxx
Quote:

> Hi
>
> This is my complete code:
>
>
> @VBSCRIPT
>
> DirF="c:\testes\teste.ual"
>
> Set objFSO = CreateObject("Scripting.FileSystemObject")
>
> If not objFSO.fileExists(DirF) then
> wscript.quit
> end if
I put the following lines into c:\test.vbs:

DirF="c:\testes\teste.ual"
Set objFSO = CreateObject("Scripting.FileSystemObject")
If not objFSO.fileExists(DirF) then

wscript.echo "Terminating the script . . ."
wscript.quit
end if
wscript.echo "Continuing with the script . . ."

I don't have a file called "c:\testes\teste.ual" and the script terminated
with the message "Terminating the script", as expected.


My System SpecsSystem Spec
Old 09-26-2008   #9 (permalink)
Henrique


 
 

Re: Detect if file exist


"Pegasus (MVP)" <I.can@xxxxxx> escreveu na mensagem
news:uSDC8I$HJHA.4884@xxxxxx
Quote:

>
> "Henrique" <wq@xxxxxx> wrote in message
> news:newscache$te7t7k$so7$1@xxxxxx
Quote:

>> Hi
>>
>> This is my complete code:
>>
>>
>> @VBSCRIPT
>>
>> DirF="c:\testes\teste.ual"
>>
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>
>> If not objFSO.fileExists(DirF) then
>> wscript.quit
>> end if
>
> I put the following lines into c:\test.vbs:
>
> DirF="c:\testes\teste.ual"
> Set objFSO = CreateObject("Scripting.FileSystemObject")
> If not objFSO.fileExists(DirF) then
>
> wscript.echo "Terminating the script . . ."
> wscript.quit
> end if
> wscript.echo "Continuing with the script . . ."
>
> I don't have a file called "c:\testes\teste.ual" and the script terminated
> with the message "Terminating the script", as expected.
>
I put the code and got the same error.

if I withdraw "wscript.quit" and put only "wscript.echo "Terminating the
script . . ."" get the same error: "Object requerid: 'wscript'" at line 6


My System SpecsSystem Spec
Old 09-26-2008   #10 (permalink)
Henrique


 
 

Re: Detect if file exist


"Henrique" <wq@xxxxxx> escreveu na mensagem
news:newscache$6iat7k$zk9$1@xxxxxx
Quote:

>
> "Pegasus (MVP)" <I.can@xxxxxx> escreveu na mensagem
> news:uSDC8I$HJHA.4884@xxxxxx
Quote:

>>
>> "Henrique" <wq@xxxxxx> wrote in message
>> news:newscache$te7t7k$so7$1@xxxxxx
Quote:

>>> Hi
>>>
>>> This is my complete code:
>>>
>>>
>>> @VBSCRIPT
>>>
>>> DirF="c:\testes\teste.ual"
>>>
>>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>>
>>> If not objFSO.fileExists(DirF) then
>>> wscript.quit
>>> end if
>>
>> I put the following lines into c:\test.vbs:
>>
>> DirF="c:\testes\teste.ual"
>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>> If not objFSO.fileExists(DirF) then
>>
>> wscript.echo "Terminating the script . . ."
>> wscript.quit
>> end if
>> wscript.echo "Continuing with the script . . ."
>>
>> I don't have a file called "c:\testes\teste.ual" and the script
>> terminated with the message "Terminating the script", as expected.
>>
>
> I put the code and got the same error.
>
> if I withdraw "wscript.quit" and put only "wscript.echo "Terminating the
> script . . ."" get the same error: "Object requerid: 'wscript'" at line
> 6
>
If I put only "wscript.echo "Continuing with the script . . ." display the
same error


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Copy/Move file and rename if destination exist PowerShell
The file hs does not exist. error on capture Virtual Server
Vista File Mgmt can't find items that exist Vista file management
The File or Folder Does Not Exist Vista General
Can't detect XP computer on network for file sharing Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46