![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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. 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
| | #4 (permalink) |
| | 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 > |
My System Specs![]() |
| | #5 (permalink) |
| | 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 Specs![]() |
| | #6 (permalink) |
| | 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 |
My System Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
| | #8 (permalink) |
| | 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 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 Specs![]() |
| | #9 (permalink) |
| | 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. > 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 Specs![]() |
| | #10 (permalink) |
| | 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 > same error |
My System Specs![]() |
![]() |
| 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 | |||