How to get proper FilePattern - building path from blocks Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
BriHecato
Posts: 42
Joined: 18 Jul 2017, 07:17

How to get proper FilePattern - building path from blocks

28 Jul 2017, 13:20

I'm trying to bite more than I can eat :)

I'm using software that need to manually link hundreds of files into excel-like-grid, and I figured out some script that can do this in very basic and rough way:
1. From windowTitle I get customer and order number
2. from row I get part of file name
3. In open dialog i'm placing (pasting) parts of path form drive to file, each time with windows autocomplete and automatch, so it looks like this:

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


%firm% , %nrz%, %gr%, are precisely trimmed substrings. Last part - file name is not precisely trimmed, files has suffixes that I don't know until I link it. That's why I send {Down} because Windows Open Dialog perform automatch/autocompletion (it's enough for me)
Horrible but efficient.

Now I want to boost this process looping whole function. But problem happens when file doesn't exist - script is sending and pressing Enter's in wrong places :)
So i figured out that I need to check in the background if file is there - what a problem - I got all the information... do I?
Writing to check if path is right:

Code: [Select all] [Download] GeSHi © Codebox Plus

fd := "\"
napv := %rfolder%%firm%%fd%%nrz%%fd%%gr%%fd%%npg2%
MsgBox, %napv%


And got "The following variable contains an illegal character "p:\briwork\january\onefirm\3422\1,5\1-3-2".... thread will exit
Why!? What happened? I haven't used "*.dxf" yet... ??? Is this comma?? Separately and combined in windows dialog it works... but here doesn't..
Last edited by BriHecato on 03 Aug 2017, 23:31, edited 2 times in total.
BoBo
Posts: 1207
Joined: 13 May 2014, 17:15

Re: Build a full path from blocks - get The following variable contains an illegal character

28 Jul 2017, 14:16

Code: [Select all] [Download] GeSHi © Codebox Plus

fd := "\"
MsgBox % rfolder . firm . fd . nrz . fd . gr . fd npg2 ; check out how to use variables in expressions
MsgBox % rfolder . firm . "\" . nrz . "\" . gr . "\" . npg2 ; same here
MsgBox %rfolder%%firm%\%nrz%\%gr%\%npg2% ; 'traditional' style

MsgBox % var := "p:\briwork\january\onefirm\3422\1,5\1-3-2" ; working fine
BriHecato
Posts: 42
Joined: 18 Jul 2017, 07:17

Re: Build a full path from blocks - get The following variable contains an illegal character

28 Jul 2017, 14:47

Prefer "traditional" style,

Alrigth - as far as we are in MsgBox it's working.
But how place this in


Of course I need to add wildcard and extension at the end
I'm doing like this:

Code: [Select all] [Download] GeSHi © Codebox Plus

star :="*.geo"
psdp := %rfolder%%firm%%nrz%\%gr%\%npg2%%star%

And "Leftmost character is illegal" ...

This way return no error:

Code: [Select all] [Download] GeSHi © Codebox Plus

fd := "\"
star :="*.geo"
psdp := % rfolder . firm . nrz . fd . gr . fd . npg2 . star

But my syntax color is broken (without ending "%" and I don;t like it ....)

Writing more:

Code: [Select all] [Download] GeSHi © Codebox Plus

If FileExist(psdp)
{
do the action
}
else
MsgBox, No file mate

And this script does nothing - I know that file is there, but i get no action neither MsgBox.

Probably I forgot about this

No way - Illegal character ...

It's late for me and probably it is obvoius, but i cannot handle this - want to build this variable with full path and wildcard instead sufix, then check if file exist then perform rest of script, else return info that file doesn't exist and finish script. Tired after this week.
User avatar
tidbit
Posts: 982
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Build a full path from blocks - get The following variable contains an illegal character

28 Jul 2017, 14:51

if you want to use traditional style, simply use = instead of :=
but traditional style has limits. like you cannot call function()'s

psdp = %rfolder%%firm%%nrz%\%gr%\%npg2%%star%
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
BoBo
Posts: 1207
Joined: 13 May 2014, 17:15

Re: Build a full path from blocks - get The following variable contains an illegal character

28 Jul 2017, 15:15

BriHecato wrote:Probably I forgot about this

No way - Illegal character ...

Well, as tidbit and me, myself and I have already mentioned, you have to check out the help file for expressions, simply for the reason that commands like FileExist() (and dozens of others) are functions - and functions expect its parameters in expression style. Using 'traditional' variables in functions will throw out errors like this.
BriHecato
Posts: 42
Joined: 18 Jul 2017, 07:17

Re: Build a full path from blocks - get The following variable contains an illegal character

28 Jul 2017, 16:32

Somehow this works, thank you for patience

Code: [Select all] [Download] GeSHi © Codebox Plus

psdp = % rfolder . firm . nrz . fd . gr . fd . npg2 . star
if FileExist(psdp)
{ Action }
Else
{MsgBox, No file mate}


Alrigth. What i would like to achieve next:
1. Check if file exist in source location "base dir of files"
2. If yes - Copy to destination location (create folder with subfolders if necessary) / if no write info to the error log
3. open dialog and link from destination location

where to look at? :)
Guest

Re: Build a full path from blocks - get The following variable contains an illegal character  Topic is solved

28 Jul 2017, 16:42

1. Get some sleep (really helps)

2. It is not ever will be If FileExist(%psdp%) with %% around your variable name.
It must be If FileExist(psdp) sans %% - that is just how it is and AHK works. Which is also shown in the thread you link to by sinkfaze - read up on it here https://autohotkey.com/docs/FAQ.htm#percent

So its either

If FileExist(psdp) ; function
See https://autohotkey.com/docs/commands/FileExist.htm

or

IfExist, %psdp% ; command
See https://autohotkey.com/docs/commands/IfExist.htm

they look similar but are different.

So you can do this

psdp = %rfolder%%firm%%nrz%\%gr%\%npg2%%star%/

or you can do this

psdp := rfolder firm nrz "\" gr "\" npg2 star ; it omits the dots so this valid to psdp := rfolder . firm . nrz . "\" . gr . "\" . npg2 . star
See https://autohotkey.com/docs/Variables.htm#concat

Have a good weekend ;)
BoBo
Posts: 1207
Joined: 13 May 2014, 17:15

Re: Build a full path from blocks - get The following variable contains an illegal character

28 Jul 2017, 16:45

I have read this and the guy also didn't get help
https://autohotkey.com/board/topic/7820 ... -function/


Well, ... as said, read the help file ...
If FileExist("e:\%dvdt%\VIDEO_TS") this won't work
If FileExist("e:\" dvdt "\VIDEO_TS") this will work
BriHecato
Posts: 42
Joined: 18 Jul 2017, 07:17

Re: Build a full path from blocks - get The following variable contains an illegal character

29 Jul 2017, 00:28

Thanks guys, this Guest's post clarified few things, I'm better in the morning :)
BoBo
Posts: 1207
Joined: 13 May 2014, 17:15

Re: Build a full path from blocks - get The following variable contains an illegal character

29 Jul 2017, 03:00

Hint
Every command that is displayed in a code box is linked with its assigned help page. Simply click on it (no need to copy a link separately).

Code: [Select all] [Download] GeSHi © Codebox Plus

SetTimer, UselessLable, % 10*1000 ; click on 'SetTimer' will open the help for it in a separate window!

Beside that, the forums "Full Editor" offers the [docs] tag. This allows to tag/link a word to its respective AHK help section - like this SetFormat
BriHecato
Posts: 42
Joined: 18 Jul 2017, 07:17

Re: Build a full path from blocks - get The following variable contains an illegal character

31 Jul 2017, 01:58

Crap - after the weekend it stopped working.... Really don't know why. After a short investigation script even skip
FileAppend, %nrz% `n , p:\laser\bkf\missinglog.txt
It even didn't create the result file!
The same for
FileAppend, %gr%: %npg2%`, , p:\laser\bkf\missinglog.txt which is bound to the if FileExist-Else

Also without all this fileappend my paths obviously are wrong despite that they were working, and even were working with FileCopy (this topic https://autohotkey.com/boards/viewtopic.php?f=5&t=35170)

Let's clarify some things - I'm building path (filepattern) new approach with some clear up
fileindest := folderbkf . nrz . fd . gr . fd . npg2 . star
where
folderbkf := "p:\laser\bkf\" is "hardcoded" (combined rfolder and firm from previous code)
nrz is trimmed substring from wintitle
fd := "\" is also "hardcoded"
gr is copied string from cell in grid - new: then replaced colon with dot
npg2 is few times trimmed from both sides string taken from cell in grid
star := "*.geo" is hardcoded new: looking for file with other extension

So I know that got
"p:\laser\bkf\"
5252 (example - but is it string or is it number when I try to concatenate ?)
"\"
1.5 (example - string or number?)
14-12-1 (example, but that kind of filename are expected - is it string or number or mathematical substraction = "1" ??)
"*.geo"

And i concatenate them
path = % folderbkf . nrz . fd . gr . fd . npg2 . star this works before
But i should use:
path := folderbkf . nrz . fd . gr . fd . npg2 . star
Unfortunately both doesn't work

full filepattern should be
p:\laser\bkf\5252\1.5\14-12-1*.geo

------------------------------------------------------

I'm writing special new separate code to get to somwhere

Code: [Select all] [Expand] [Download] GeSHi © Codebox Plus


I'm 100% sure file is there but script returns this
no frakin file.png
no frakin file.png (8.97 KiB) Viewed 169 times


It really doesn;t matter if I use
path = % ...
or
path := ....
if I put
fd := "\"
or if i write
. "\" .

-----------------------

Is it connected to the fact that path leads to network drive??

After another test it CAN find file on desktop
got file.png
got file.png (62.01 KiB) Viewed 154 times

but CANNOT on NAS
no file2.png
no file2.png (6.15 KiB) Viewed 156 times
BriHecato
Posts: 42
Joined: 18 Jul 2017, 07:17

Re: How to get proper FilePattern - building path from blocks

31 Jul 2017, 03:13

How it looks in the real life app
xlaser.png
(56.04 KiB) Not downloaded yet


-------------------

NO frakin WAY!!! Old script works... i've just done this as JoeWinograd suggest for debugging purposes
Please post the results from this MsgBox statement:

Code: [Select all] [Download] GeSHi © Codebox Plus

MsgBox,,debug,folderbkf=%folderbkf%`nnrz=%nrz%`nfd=%fd%`ngr=%gr%`nnpg2=%npg2%`nstar=%star%

Put that line right after:
fileindest := folderbkf . nrz . fd . gr . fd . npg2 . star


Now I'm sure that is the Win10+networkDrive+AHK combined issue....

Return to “Ask For Help”

Who is online

Users browsing this forum: arytinki, Bing [Bot], Yahoo [Bot], ZhanToO and 47 guests