Sign in to follow this  
Followers 0
Jon Mason

manipulate FileOpenDialog results

4 posts in this topic

I manage the apps on about 20 servers and pushing out updates to files can be a pain. I wrote a cool app that helps me use mirror folders using robocopy (I'm not getting into the xxcopy vs. robocopy debate), but now I want to build in the function to just copy a select few files (not folders) out to several server locations. I'm using the FileOpenDialog function and I know the results are something I can work with, but I'm having some issues. Lets say I get a result back of:

H:\Inventory|Components.doc|grps.txt

I need to turn that into:

robocopy "H:\Inventory" \\[someServer]\vol\folder "Components.doc" "grps.txt"

This wouldn't be so hard if it wasn't for splitting the initial statement in half with the destination server.

Any thoughts or best practices?

I was thinking someting like:

$fileCopy = FileOpenDialog("Select Files", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "All (*.*)", 1 + 4)
$fileCopy = StringReplace($fileCopy, "|", '" "')
$folderOpen = StringReplace($fileCopy, '\|', '\--"')
$folderOpen = StringReplace($folderOpen, '\" "', '\--"')
$folderOpen = '"' & $fileCopy & '"'
...but then I'm stuck.

Share this post


Link to post
Share on other sites



Welcome to the forums!

There are many ways to accomplish this.

Convoluted, quick:

$fileCopy = FileOpenDialog("Select Files", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "All (*.*)", 1 + 4)
ConsoleWrite('Robocopy "' & StringLeft($fileCopy, StringInStr($fileCopy, "|") - 1) & '" \\server\share\path "' & StringReplace(StringRight($fileCopy, StringLen($fileCopy) - StringInStr($fileCopy, "|")), "|", '" "') & '"' & @LF)oÝ÷ ØF¬êí¢éÝz»-jwn²)ཪâi¹^±«­¢+ØÀÌØí¥±
½Áäô¥±=Á¹¥±½ ÅÕ½ÐíM±Ð¥±ÌÅÕ½Ðì°ÅÕ½ÐìèéìÈÁÀÑÀ´Í´ÄÀØäµÉà´ÀàÀÀÉÌÀÌÀåôÅÕ½Ðì°ÅÕ½Ðí±° ¨¸¨¤ÅÕ½Ðì°Ä¬Ð¤)±½°ÀÌØíÉÌôMÑÉ¥¹MÁ±¥Ð ÀÌØí¥±
½Áä°ÅÕ½ÐíðÅÕ½Ðì¤)±½°ÀÌØí½±É=Á¸ôÀÌØíÉÍlÅt)±½°ÀÌØí¥±MÁôÅÕ½ÐìÅÕ½Ðì)½ÈÀÌØíàôÈQ¼ÀÌØíÉÍlÁt(ÀÌØí¥±MÁôÀÌØí¥±MÁµÀìÌäìÅÕ½ÐìÌäìµÀìÀÌØíÉÍlÀÌØíátµÀìÌäìÅÕ½ÐìÌäì)9áÐ)
½¹Í½±]É¥Ñ ÌäíI½½½ÁäÅÕ½ÐìÌäìµÀìÀÌØí½±É=Á¸µÀìÌäìÅÕ½ÐìÅÕ½ÐìÀäÈìÀäÈíÍÉÙÈÀäÈíÍ¡ÉÀäÈíÁÑ ÅÕ½ÐìÌäìµÀìÀÌØí¥±MÁµÀì1¤
Run it through Scite to make sure the syntax is proper, then convert ConsoleWrite to Run/RunWait.

[font="Tahoma"]"Tougher than the toughies and smarter than the smarties"[/font]

Share this post


Link to post
Share on other sites

Well, I went home and thought about it and like a thorn, couldn't get it out of my head. Here's what I ended up with. Let me know what you think. A little bigger than wha you came up with, but it works. :D

$desCopy = "\\L060gozen1\vol1\zenapps" ;passed in from an array


$fileOpenReturn = FileOpenDialog("Select Files...", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "All (*.*)", 1 + 4 )
$fileOpenLen = StringLen($fileOpenReturn)

$return = _Parce($fileOpenLen, $fileOpenReturn, "|", "L")
if StringLen($return) <> $fileOpenLen Then
    $orgCopy = $return
    $returnLen = StringLen($return)
    $files = StringRight($fileOpenReturn, $fileOpenLen - ($returnLen + 1))
    $files = '"' & StringReplace($files, "|", '" "') & '"'
    
ElseIf StringLen($return) = $fileOpenLen Then
    $return = _Parce($fileOpenLen, $fileOpenReturn, "\", "R")
    $returnLen = StringLen($return)
    $orgCopy = StringLeft($fileOpenReturn, $fileOpenLen - ($returnLen + 1))
    $files = StringRight($fileOpenReturn, StringLen($return))
    $files = '"' & $files & '"'
Else
    ;MsgBox(0,"3",$return)
EndIf

$runCmd = "robocopy " & '"' & $orgCopy & '"' & " " & $desCopy & " " & $files
MsgBox(0, "Your copy statement", $runCmd)

Func _Parce($varLen, $lookIn, $look, $leftOrRight)
    
    $varCount = "0"
    $moveCount = "1"
    $ParceCur = "0"
    $loopCount = "0"
    
    If $leftOrRight = "L" Then
        Do 
            $moveCount = $moveCount + 1 
            $ParceLeft = StringLeft($lookIn, $moveCount - "1") 
            $ParceLeftLen = StringLen($ParceLeft) 
            $x = StringRight($ParceLeft, "1") 
            $loopCount = $loopCount + 1 
            if $x = $look Then ; $look = what the var your looking for
                $varCount = $varCount + 1
                
            EndIf
            if $loopCount = $varLen Then ExitLoop
        Until $varCount = "1" ;change this point count to the number of octets you want to compair
            
        If $loopCount = $varLen Then
            $var = $lookIn
        Else
            $var = StringLeft($lookIn, $loopCount - 1)
        EndIf
        
    ElseIf $leftOrRight = "R" Then
        Do 
            $moveCount = $moveCount + 1
            $ParceRight = StringRight($lookIn, $moveCount - "1")
            $ParceRightLen = StringLen($ParceRight)
            $x = StringLeft($ParceRight, "1")
            $loopCount = $loopCount + 1 
            if $x = $look Then ; $look = what the var your looking for
                $varCount = $varCount + 1
            EndIf
            if $loopCount = $varLen Then ExitLoop
        Until $varCount = "1" ;change this point count to the number of octets you want to compair
    
        If $loopCount = $varLen Then
            $var = $lookIn
        Else
            $var = StringRight($lookIn, $loopCount - 1)
        EndIf
    EndIf
    
    Return $var
EndFunc

Share this post


Link to post
Share on other sites

Welcome to the forums!

There are many ways to accomplish this.

Convoluted, quick:

$fileCopy = FileOpenDialog("Select Files", "::{20D04FE0-3AEA-1069-A2D8-08002B30309D}", "All (*.*)", 1 + 4)
ConsoleWrite('Robocopy "' & StringLeft($fileCopy, StringInStr($fileCopy, "|") - 1) & '" \\server\share\path "' & StringReplace(StringRight($fileCopy, StringLen($fileCopy) - StringInStr($fileCopy, "|")), "|", '" "') & '"' & @LF)oÝ÷ ØF¬êí¢éÝz»-jwn²)ཪâi¹^±«­¢+ØÀÌØí¥±
½Áäô¥±=Á¹¥±½ ÅÕ½ÐíM±Ð¥±ÌÅÕ½Ðì°ÅÕ½ÐìèéìÈÁÀÑÀ´Í´ÄÀØäµÉà´ÀàÀÀÉÌÀÌÀåôÅÕ½Ðì°ÅÕ½Ðí±° ¨¸¨¤ÅÕ½Ðì°Ä¬Ð¤)±½°ÀÌØíÉÌôMÑÉ¥¹MÁ±¥Ð ÀÌØí¥±
½Áä°ÅÕ½ÐíðÅÕ½Ðì¤)±½°ÀÌØí½±É=Á¸ôÀÌØíÉÍlÅt)±½°ÀÌØí¥±MÁôÅÕ½ÐìÅÕ½Ðì)½ÈÀÌØíàôÈQ¼ÀÌØíÉÍlÁt(ÀÌØí¥±MÁôÀÌØí¥±MÁµÀìÌäìÅÕ½ÐìÌäìµÀìÀÌØíÉÍlÀÌØíátµÀìÌäìÅÕ½ÐìÌäì)9áÐ)
½¹Í½±]É¥Ñ ÌäíI½½½ÁäÅÕ½ÐìÌäìµÀìÀÌØí½±É=Á¸µÀìÌäìÅÕ½ÐìÅÕ½ÐìÀäÈìÀäÈíÍÉÙÈÀäÈíÍ¡ÉÀäÈíÁÑ ÅÕ½ÐìÌäìµÀìÀÌØí¥±MÁµÀì1¤
Run it through Scite to make sure the syntax is proper, then convert ConsoleWrite to Run/RunWait.
That worked if you have more than one file. But this program needs to be versatile to do one or more. However, by looking at your code, I'm sure you could handle that too. ;-) I will play with what you gave me and I'm sure yours will work better if I tweak it.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0