|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
Problem with FileExists method and executing del command
I have 3 problems:
The following code is not deleting the file. After executing my vbscript script, the file still exists. I've checked permissions and I have full control of the files and they are not flagged read-only: Code:
strsfxcllogsrc = "c:\sfxcllog.txt" strsfxcldest = "c:config.ini" Set objdlt = objshll.Exec( "cmd /c del /q" & " " & strsfxcllogsrc ) The following code is returning a false negative: Code:
Set objfso = CreateObject( "Scripting.FileSystemObject" )
If objfso.FileExists( strsfxcldest ) = True Then
Set objdlt = objshll.Exec( "cmd /c del /q" & " " &
strsfxcllogsrc )
WScript.Echo "Writing new configuration file."
WScript.Echo
Else
WScript.Echo "Download failed!"
WScript.Echo "Try re-running upsconfig. If the
problem" _
& " persists, check your network connection."
Set objdlt = objshll.Exec( "cmd /c del /q " &
strsfxcllogsrc & " " & strsfxcldest )
WScript.Quit
End If
The following code does not read all of the file text into the variable strsfxcllog so my regex does not match the text it's looking for: Code:
If objfso.FileExists( strsfxcllogsrc ) Then
Set objread = objfso.OpenTextFile( strsfxcllogsrc,
forread )
strsfxcllog = objread.ReadAll
If reftpputsccss.Test( strsfxcllog ) = True Then
WScript.Echo "Uploading configuration file!"
Set objdlt = objshll.Exec( "cmd /c del /q " &
strsfxcldest & strsfxcllogsrc )
WScript.Echo
Else
WScript.Echo "Configuration file uploaded!" _
& VbCrLf & "Please check your Network
connection and re-run" _
& " upsconfig."
'Cleanup
WScript.Echo "Deleting files:" & VbTab &
strsfxcldest _
& VbCrLf & strsfxcllogsrc
Set objdlt = objshll.Exec("cmd /c del /q " _
& strsfxcldest & " " & strsfxcllogsrc )
WScript.Quit
End If
Else
WScript.Echo "Log file does not exist! Please
check your network connection and Re-run
upsconfig."
Set objdlt = objshll.Exec( "cmd /c del /q " &
strsfxcldest )
WScript.Echo "Upload did not complete
successfully. " _
& "Please check with your system administrator
(CRC) to confirm " _
& "you have the appropriate privileges to write
files to your " _
& "disk drive and re-execute upsconfig.exe. If
this does not " _
& "resolve the issue, please contact the PCG."
WScript.Quit
End If
Thanks in advance for the favor! |
|
#2
|
|||
|
|||
|
try to use KILL to delete any file.
better try with on error ....resume next to avoid any error if the file does not exist. |
|
#3
|
||||
|
||||
|
VB6, I assume?
You said that you're getting a false negative for a whole block of code. Considering that it's an if-else, I assume it's just this line that is returning False when it should return True... Code:
objfso.FileExists(strsfxcldest) There's also a place where you forgot to concatenate a " " between strsfxcldest and strsfxcllogsrc. The delete would fail. |
|
#4
|
||||
|
||||
|
Quote:
Is there another way besides KILL? I don't have it on my system and neither will the users who will use my script. I've used KILL before on other systems to kill a process, but I did not know you could use it like del. If this is true, then I hope there is a way I can package KILL with my script! Quote:
|
|
#5
|
|||||
|
|||||
|
Quote:
Quote:
yeah, my typo! Quote:
Code:
strsfxcllog = objread.ReadAll |
|
#6
|
|||
|
|||
|
Quote:
And to further clarify, your original code is using the filesystem object, which isn't any of the above languages, the filesystem object is a scripting com object that can be used by many different languages. The FSO is part of the microsoft scripting engine, and is documented with example code in the msdn library.
__________________
====== Doug G ====== "Hide, hide witch! The good folk come to burn thee. Their keen enjoyment hid behind their gothic mask of duty." -Mark Clifton |
|
#7
|
|||
|
|||
|
Quote:
i think you just proved my point about the interchangeability of these languages. if the fso object can be used by more than one language, i'm guessing there are cases where determining the language is difficult due to ambiguity. but again, this is just my guess. thanks for your reply, it was helpful. |
|
#8
|
||||
|
||||
|
Quote:
(And evidently you do, considering the username you chose. We just can't assume the problem is always going to be in VBS based on that.) We have good reason for needing to know such details. Even though there are many similarities between VB5/6, VBA, and VBS, there are also differences between them (including limitations in the latter two) that can have a significant impact on what suggestions and advice we offer. Quote:
|
|
#9
|
|||
|
|||
|
Quote:
yes, i'm using vbs, sorry for the confusion. i'm not sure what characters are being added or if that's the problem. i'm going to loop through each line of strsfxcllog -assuming that there is more than one line of text- and try matching it against my regular expression. let you know if that's any better. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Problem with FileExists method and executing del command |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|