Is there a way to open folder with partial information?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Laie
Posts: 55
Joined: 18 Mar 2016, 06:45

Is there a way to open folder with partial information?

21 Mar 2016, 10:13

As an example, I have a structure like this:

C:\Projects\16-100
C:\Projects\16-101
C:\Projects\16-102
...

Except that there is also descriptive information after the number:

C:\Projects\16-100-FirstProject-OtherDescriptiveStuff
C:\Projects\16-101-SecondProject-Canceled
C:\Projects\16-102-OtherStuff
...

I want to open a folder with Autohotkey (and then save documents there etc.) using only the number of the folder. Is there some kind of way to use "wildcards" or some other method to still open the folder?
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Is there a way to open folder with partial information?

21 Mar 2016, 10:24

What do you mean by opening?

I haven't done any testing, but I'd do this:

Code: Select all

Loop, Files, C:\Programs\16-100*, D
{
Run, A_LoopFileFullPath
Break
}
This will run the first match that begins with 16-100 and open it up in explorer.
Laie
Posts: 55
Joined: 18 Mar 2016, 06:45

Re: Is there a way to open folder with partial information?

21 Mar 2016, 12:04

Thanks.

I think I was unclear with "open". What I want to do is create folders and files in that particular folder.
Shadowpheonix
Posts: 1259
Joined: 16 Apr 2015, 09:41

Re: Is there a way to open folder with partial information?

21 Mar 2016, 13:24

You cannot create a file or folder using a wildcard. Wildcards can only be used with items that already exist.
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Is there a way to open folder with partial information?

21 Mar 2016, 13:48

If you're creating folders and files with AHK, you've at least got a way to capture the preceeding part of the file path. Just use this:

Code: Select all

Loop, Files, C:\Programs\16-100*, D
{
path:=A_LoopFileFullPath
Break
}
FileAppend, Hello World, %path%\MyNewFile.txt
return
(I'm not aware of a native AHK command for creating a new folder, but, there may well be. Edit: Here it is: FileCreateDir)
User avatar
tidbit
Posts: 1273
Joined: 29 Sep 2013, 17:15
Location: USA

Re: Is there a way to open folder with partial information?

21 Mar 2016, 13:51

Creates a directory/folder.
fileCreateDir, DirName
rawr. fear me.
*poke*
Is it December 21, 2012 yet?
User avatar
YoucefHam
Posts: 372
Joined: 24 Aug 2015, 12:56
Location: Algeria
Contact:

Re: Is there a way to open folder with partial information?

21 Mar 2016, 14:00

Laie wrote:As an example, I have a structure like this:

C:\Projects\16-100
C:\Projects\16-101
C:\Projects\16-102
...

Except that there is also descriptive information after the number:

C:\Projects\16-100-FirstProject-OtherDescriptiveStuff
C:\Projects\16-101-SecondProject-Canceled
C:\Projects\16-102-OtherStuff
...

I want to open a folder with Autohotkey (and then save documents there etc.) using only the number of the folder. Is there some kind of way to use "wildcards" or some other method to still open the folder?

Hi try this:

Code: Select all

Loop, Files, 16-100*, D
{
	path:=A_LoopFileFullPath
	Break
}
IfExist, %path%
{
	Run, %path%
	FileAppend, Existing Folder`n, %path%\MyNewFile.txt
}
else
{
	Run %comspec% /c "MKDIR 16-100" ;Command window, More at : http://ss64.com/nt/
	Run, 16-100\
	FileAppend, New Folder`n, 16-100\MyNewFile.txt
}
return
:wave: There is always more than one way to solve a problem. ;)
Laie
Posts: 55
Joined: 18 Mar 2016, 06:45

Re: Is there a way to open folder with partial information?

22 Mar 2016, 04:57

YoucefHam: Thanks, that just about did it.

The only problem I am running into is that I have a variable further up in the program for the project number.

Let's say that vprojectnumber gets set equal to 16-102

The command "Loop, Files ..." apparently doesn't allow variables in its file pattern.

So this does not work (I also tried combinations of quotation marks and percentage signs):

Loop, Files, C:\Projects\%projectnumber%*, D

Is there some way to build up the path with a variable and then insert it into the file pattern for "Loop, Files ..."? Or some other way around this?
User avatar
Exaskryz
Posts: 2882
Joined: 17 Oct 2015, 20:28

Re: Is there a way to open folder with partial information?

22 Mar 2016, 05:38

Variables do work in the file path. What you have should work; Loop, Files, C:\Projects\%projectnumber%*, D. Double check that projectnumber has the value you want with MsgBox %projectnumber% before the loop file is run. I noticed you said that it was vprojectnumber is 16-102 . Two possible problems I can think of. One, your variable actually does have the v in it. I assume this is a GUI though. If it is a GUI, and in the gui control you used "vprojectnumber", then the actual name of the variable is "projectnumber". However, if this isn't a GUI, double check if the v should be there or not, and also double check you're not using the := operator. That operator would treat 16-102 as an expression, which treats it as 16 minus 102, which is -86.
Laie
Posts: 55
Joined: 18 Mar 2016, 06:45

Re: Is there a way to open folder with partial information?

22 Mar 2016, 06:05

Exaskryz,

Thanks - I got it working. I just had a typo.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Draken, Google [Bot], oktavimark, Spawnova, william_ahk and 283 guests