Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 02-29-2012, 05:16 AM
Duppie Duppie is offline
Registered User
 
Join Date: Feb 2012
Posts: 3
Delete content in directory and then directory itself

Hi,

How can I, from the listing below, only obtain the names of the directories and feed that to delete the content and directory itself?

>file:\ # dir | match DIR
02/29/2012 11:16a <DIR> Test
02/29/2012 11:21a <DIR> pack
02/29/2012 11:21a <DIR> comp
02/29/2012 11:21a <DIR> collect

Command for delete files in directory will be >file:\ #delete <directory>\*.*
Command for delete directory itself will be >file:\ #rd <directory>

Thanks for the assistance.

Duppie
Reply With Quote
  #2  
Old 02-29-2012, 10:21 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Duppie,

What VanDyke Software product are you using?

What is the version and operating system?

What scripting language do you intend to use?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 02-29-2012, 08:37 PM
Duppie Duppie is offline
Registered User
 
Join Date: Feb 2012
Posts: 3
@begagnon

The version of my SecureCRT is 6.7.4 (build 354). The PC from where the script will be run is an XP SP3 and I intend to use VBScript.

I have written the following function, but it does not work properly and I am are sure their are better ways to do this. The problem with the function below is that at first it returns the "CurrentRow" which is the command itself so i get a "Blank" at first then the directories and secondly it does all of this twice. Thanks for the assistance.

Duppie


Function Delete_DIR()
crt.Screen.Synchronous = True
szShellPrompt = "\ # "
Dim szLine
Dim vTokens
crt.screen.send "dir | match DIR" & vbcr

Do
nResult = crt.Screen.WaitForStrings (vbcr, szShellPrompt)
if nResult = 2 then exit do
szLine = crt.Screen.Get(crt.Screen.CurrentRow, 0, crt.Screen.CurrentRow, crt.Screen.Columns)
vTokens = Split(szLine, " ")
crt.Screen.Send "delete /" & vTokens(18) & "/*.* force" & vbcr
crt.Screen.Send "rd /" & vTokens(18) & " force" & vbcr

Loop

crt.Screen.Synchronous = False

End Function
Reply With Quote
  #4  
Old 03-01-2012, 03:18 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Duppie,

If you want a simple solution, I have to ask if there is ever the possibility of a wordspace being included in the directory name?

If so, the solution is Regular Expressions. More on that once you respond to the above.

If not, you can use InStrRev to find the position of the ">" angle bracket and then you can use the Mid() function to parse the directory name.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 03-01-2012, 05:23 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Duppie,

The RegExp solution will allow you to "do away" with the Do Loop. That was likely part of the problem with your earlier results, as you were still processing results, yet you were trying to execute the Send to delete and rd the directories.

Code:
strData = crt.Screen.ReadString(szShellPrompt)

Set re = New RegExp
re.MultiLine =  True
re.Global = True
re.Pattern = "\s+<DIR>\s+([^\r\n]+)$"

If re.Test(strData) Then
    Set objMatches = re.Execute(strData)
    For Each objMatch in ObjMatches
        strDir = objMatch.Submatches(0)
        crt.Dialog.MessageBox "Directory found: " & strDir
    Next
Else
    crt.Dialog.MessageBox "No directory pattern was found in the following data: " & _
        vbcrlf & strData
End If
In your case, in place of the message box in the For loop, you can send your commands.

Please remember you should never have two Sends in a row. This best practice is discussed in the scripting manual available on our website here. (Section 4.2)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #6  
Old 03-01-2012, 09:29 PM
Duppie Duppie is offline
Registered User
 
Join Date: Feb 2012
Posts: 3
Hi Brenda,

Much appreciated. Must have missed that in the "scripting essentials" guide. Anyway, your script / solution works like a charm. Thanks Again.

Duppie
Reply With Quote
  #7  
Old 03-02-2012, 09:09 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Duppie,

Excellent! Thanks for posting an update.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 11:38 AM.