Sign in to follow this  
Followers 0
Vos

Unknown Character

5 posts in this topic

Hello,

i posted on here a few days ago and the information i got helps me a lot so i am hoping for a repeat. my new problem is a more generic question. i have a mathcad file located on the server that i am opening with shellexecute. here is the code that works

$manuf = "Pan"

$Model = "NCR18650D"

ShellExecute("\\vette\database\" & $manuf & "\" & $Model & "\configs_check_rev18.xmcd", "", "\\vette02\database\" & $manuf & "\" & $Model, "open")

my question is how do i write a general script to accept the .xmcd file if the rev18 portion of it changes. this file get modified fairly regularly and the only thing that changes is the 18, which increment up every change. i have seen the use of the * character in other scripts, but here are scripts i have tried that don't seem to work.

ShellExecute("\\vette\database\" & $manuf & "\" & $Model & "\*.xmcd", "", "\\vette02\database\" & $manuf & "\" & $Model, "open")

ShellExecute("\\vette\database\" & $manuf & "\" & $Model & "*.xmcd", "", "\\vette02\database\" & $manuf & "\" & $Model, "open")

ShellExecute("\\vette\database\" & $manuf & "\" & $Model & "\configs_check_rev**.xmcd", "", "\\vette\database\" & $manuf & "\" & $Model, "open")

ShellExecute("\\vette\database\" & $manuf & "\" & $Model & "\configs_check_rev*.xmcd", "", "\\vette\database\" & $manuf & "\" & $Model, "open")

Thanks in advanced for the help.

-Vos

Share this post


Link to post
Share on other sites



Look at findfilefirst and findfilenext to find the xmcd files. You'd then need to find a criterion to identify the most appropriate one [or just use the only one, if there is only ever one such file present at a time].

Or load files to array with _FileListToArray using .xcmd as the filter.

William

Share this post


Link to post
Share on other sites

Do you mean that you want to shellexecute the .xmcd file with the highest number??? Then you I think you need something like this:

$manuf = "Pan"
$Model = "NCR18650D"
$highestvalue = 0

For $i = 0 To 99;I think 99 versions are enough??? If you need more just set another 9 after that, then can you use 900 versions more
   If FileExists("\\vette\database\" & $manuf & "\" & $Model & "\configs_check_rev" & $i & ".xmcd") Then;Checks if the file exists and if so, the $highestnumber is set to the $i value
      $highestnumber = $i;Set $highestnumber to $i
   EndIf
Next
ShellExecute("\\vette\database\" & $manuf & "\" & $Model & "\configs_check_rev" & $highestvalue & ".xmcd", "", "\\vette\database\" & $manuf & "\" & $Model, "open");ShellExecutes the .xmcd with the highest value, by example 34

This should work, I haven't tested, because I don't have that kind of hierarchy of my files. :)


PowerSlide2UnlockiPhone look-a-like program you can use to lock your pc, you can't access your desktop again until the password is entered and the slider slided to the right. (really proud of it)-- After a time AutoIt and Windows, I switched to Mac. Don't expect me to answer anymore.

Share this post


Link to post
Share on other sites

Thank you both for the reply's i will for sure use your example AppTux, cant believe i didn't think of doing that. but on a more generic question does the * key not represent "Any Character"? Or is there a key that does such? I have other uses where it would come in handy.

-Vos

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi Vos,

some functions can use the "*" as an any-character replacement and some don't. For example _FileListToArray does, because the result is an array that has a variable length. In contrary, if you have ShellExecute(), and you want to use the "*", what do you think ShellExecute will open? All files that will be found? :) ShellExecute (even if it could) also does not know which of the many choices a resulting filelist it should take.

So, "single-choice functions" normally don't support wildcards. :)

As a small enhancment to AppTux's script you may want to use sht like this:

#include <file.au3>
#include <array.au3>

$s_path = @ScriptDir

ShellExecute(_LastFile($s_path, "txt*.txt"), "", $s_path)

Func _LastFile($path, $pattern, $delim="*")
    Local $a_files, $a_files2, $a_temp, $i_index

    $a_files = _FileListToArray($path, $pattern)
    $a_temp = StringSplit($pattern, $delim)
    If Not IsArray($a_temp) Or $a_temp[0] <> 2 Then Return SetError(1, 0, 0)
    $a_files2 = $a_files

    For $i = 1 To $a_files2[0]
        $a_files2[$i] = StringTrimRight(StringTrimLeft($a_files[$i], StringLen($a_temp[1])), StringLen($a_temp[2]))
    Next
    $i_index = _ArrayMaxIndex($a_files2, 1, 1)

    Return SetError(0, 0, $path & "\" & $a_files[$i_index])
EndFunc

This will not stop at 99 (100) and really return the (in this case a txt file) file and path with the highest number.

:P

Edited by Hannes123

Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

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