Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old May 2nd, 2008, 10:38 AM
vbscodr vbscodr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 5 vbscodr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m
Reputation Power: 0
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!

Reply With Quote
  #2  
Old May 6th, 2008, 04:41 AM
debasisdas debasisdas is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2007
Location: Bangalore, India
Posts: 49 debasisdas Negative: is most likely a SPAMMER and a traitor to the cause. 
Time spent in forums: 1 Day 12 h 51 m 13 sec
Reputation Power: 0
Send a message via ICQ to debasisdas Send a message via AIM to debasisdas Send a message via MSN to debasisdas Send a message via Yahoo to debasisdas Send a message via Google Talk to debasisdas Send a message via Skype to debasisdas
Facebook MySpace Orkut
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.
Comments on this post
LyonHaert disagrees: On Error Resume Next is evil.
zynder disagrees: Not a very good advice buddy. This line of code is what I hate most.

Reply With Quote
  #3  
Old May 6th, 2008, 09:44 AM
LyonHaert's Avatar
LyonHaert LyonHaert is offline
Arcane Scribbler
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2005
Location: Indianapolis, IN
Posts: 1,602 LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 16 h 6 m 25 sec
Reputation Power: 364
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)
However, you assign "c:config.ini" to that variable. Shouldn't it be "c:\config.ini"?

There's also a place where you forgot to concatenate a " " between strsfxcldest and strsfxcllogsrc. The delete would fail.
__________________
Joel B Fant - LyonHaert.net

2 + 2 is... 10... in base 4

Reply With Quote
  #4  
Old May 7th, 2008, 09:43 PM
vbscodr vbscodr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 5 vbscodr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m
Reputation Power: 0
Quote:
Originally Posted by debasisdas
try to use KILL to delete any file.

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:
better try with on error ....resume next to avoid any error if the file does not exist.
Maybe I will do this after I know my script is working correctly.

Reply With Quote
  #5  
Old May 7th, 2008, 10:10 PM
vbscodr vbscodr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 5 vbscodr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m
Reputation Power: 0
Quote:
Originally Posted by LyonHaert
VB6, I assume?
not sure i understand your question. as far as i know, i'm using vbs not sure what version. to me it seems vb, vbs, jscript, vb.net are all pretty similar and somewhat interchangeable?
Quote:

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)
However, you assign "c:config.ini" to that variable. Shouldn't it be "c:\config.ini"?

yeah, my typo!

Quote:
There's also a place where you forgot to concatenate a " " between strsfxcldest and strsfxcllogsrc. The delete would fail.
thanks, i'll fix that and let you know how it goes. still getting false negative though. i think it has something to do with the following:
Code:
strsfxcllog = objread.ReadAll
when the file is read some extra characters are added causing my regex to fail. any ideas?

Reply With Quote
  #6  
Old May 7th, 2008, 11:19 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 12th Plane (10500 - 10999 posts)
 
Join Date: Jun 2003
Posts: 10,715 Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level)Doug G User rank is Brigadier General (60000 - 70000 Reputation Level) 
Time spent in forums: 1 Month 21 m 37 sec
Reputation Power: 688
Quote:
not sure i understand your question. as far as i know, i'm using vbs not sure what version. to me it seems vb, vbs, jscript, vb.net are all pretty similar and somewhat interchangeable?
Not at all. If you don't know what technology you're using, you need to do some preliminary homework. There is extensive documentation of these different languages on the Microsoft website, among other places. If these languages were in fact interchangeable why would they all exist?

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

Reply With Quote
  #7  
Old May 8th, 2008, 12:40 AM
vbscodr vbscodr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 5 vbscodr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m
Reputation Power: 0
Quote:
Originally Posted by Doug G
Not at all. If you don't know what technology you're using, you need to do some preliminary homework. There is extensive documentation of these different languages on the Microsoft website, among other places. If these languages were in fact interchangeable why would they all exist?

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.


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.

Reply With Quote
  #8  
Old May 8th, 2008, 09:44 AM
LyonHaert's Avatar
LyonHaert LyonHaert is offline
Arcane Scribbler
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Jun 2005
Location: Indianapolis, IN
Posts: 1,602 LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level)LyonHaert User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 16 h 6 m 25 sec
Reputation Power: 364
Quote:
Originally Posted by vbscodr
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.
Difficult for us, since we can only infer based on what other information you give us if you don't explicitly tell us what language/platform/etc. you're using. You, on the other hand, should most certainly know what you're using.

(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:
Originally Posted by vbscodr
when the file is read some extra characters are added causing my regex to fail. any ideas?
What kind of extra characters? Carriage returns and linefeeds? Or something else?

Reply With Quote
  #9  
Old May 8th, 2008, 09:58 AM
vbscodr vbscodr is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 5 vbscodr User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 12 m
Reputation Power: 0
Quote:
Originally Posted by LyonHaert
Difficult for us, since we can only infer based on what other information you give us if you don't explicitly tell us what language/platform/etc. you're using. You, on the other hand, should most certainly know what you're using.

(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.

What kind of extra characters? Carriage returns and linefeeds? Or something else?


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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Problem with FileExists method and executing del command


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |