AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

New Built-In File Loop Variable: A_LoopFileNameNoExt
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
instantrunoff



Joined: 13 Jan 2008
Posts: 62

PostPosted: Mon Apr 21, 2008 12:23 am    Post subject: New Built-In File Loop Variable: A_LoopFileNameNoExt Reply with quote

For specifying a file's name without its extension within a file-loop.
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2328

PostPosted: Mon Apr 21, 2008 12:53 am    Post subject: Reply with quote

Code:

Loop, c:\*.*
{
  StringTrimRight, OutputVar, A_LoopFileName, (A_LoopFileExt <> "") ? (StrLen(A_LoopFileExt) + 1) : 0
  MsgBox, 68,, Current File: %A_LoopFileName%`n No extension: %OutputVar%`n`nWould you like to continue?
  IfMsgBox No
    Break
}
MsgBox Have Fun :)
Back to top
View user's profile Send private message Visit poster's website
instantrunoff



Joined: 13 Jan 2008
Posts: 62

PostPosted: Mon Apr 21, 2008 1:00 am    Post subject: Reply with quote

Yes, that's true. Alternatively, one could use simply
Code:
SplitPath, %A_LoopFileName%,,,,LoopFileNameNoExt

I think, though, that if OutNameNoExt is available in SplitPath, a similar function should be available within file loops for consistency. (Plus, I didn't know about SplitPath when I started this thread.)
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2328

PostPosted: Mon Apr 21, 2008 1:00 am    Post subject: Reply with quote

another...
Code:
  OutputVar := SubStr(A_LoopFileName, 1, StrLen(A_LoopFileName) - ((A_LoopFileExt <> "") ? (StrLen(A_LoopFileExt) + 1) : 0))
Back to top
View user's profile Send private message Visit poster's website
Ian



Joined: 15 Jul 2007
Posts: 1077
Location: Enterprise, Alabama

PostPosted: Mon Apr 21, 2008 1:16 am    Post subject: Reply with quote

There would be confusion between files with the same names.
Back to top
View user's profile Send private message
instantrunoff



Joined: 13 Jan 2008
Posts: 62

PostPosted: Mon Apr 21, 2008 1:18 am    Post subject: Reply with quote

Ian wrote:
There would be confusion between files with the same names.

I don't understand what you mean.
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2328

PostPosted: Mon Apr 21, 2008 1:18 am    Post subject: Reply with quote

another...
Code:
  OutputVar := RegExMatch(A_LoopFileName, "(.*)\.(.*)$", SubPat) ? SubPat1 : A_LoopFIleName
Back to top
View user's profile Send private message Visit poster's website
corrupt



Joined: 29 Dec 2004
Posts: 2328

PostPosted: Mon Apr 21, 2008 1:19 am    Post subject: Reply with quote

instantrunoff wrote:
Ian wrote:
There would be confusion between files with the same names.

I don't understand what you mean.
Same filenames but with different extensions?
Back to top
View user's profile Send private message Visit poster's website
instantrunoff



Joined: 13 Jan 2008
Posts: 62

PostPosted: Mon Apr 21, 2008 1:25 am    Post subject: Reply with quote

corrupt wrote:
instantrunoff wrote:
Ian wrote:
There would be confusion between files with the same names.

I don't understand what you mean.
Same filenames but with different extensions?

Are you arguing against such a file loop variable? I'm not sure I understand. If you're wondering why someone would want this, it's useful for acting upon windows that have titles that include a file's name but not its extension. The variable I'm proposing would also be useful for conversion utilities that convert one file format to another (e.g. mp3 to wav). Also, I can imagine it would be useful for file organization if you had several files corresponding to a particular project that had the same name but different types (e.g. powerpoint slide show + mp3 of speech). I've encountered all of these scenarios.
Back to top
View user's profile Send private message Visit poster's website
Ian



Joined: 15 Jul 2007
Posts: 1077
Location: Enterprise, Alabama

PostPosted: Mon Apr 21, 2008 1:43 am    Post subject: Reply with quote

Yes, I am arguing. If you are looping over a dir with the files:

Code:
1.txt
3.bmp
1.png


There would be confusion when searching for the file.

So if you used

Code:
Loop, *.* {
   If (A_LoopFileNameNoExt = 1) {
      MsgBox,, FileFound, The file is in posotion %A_Index%
   }
}


When searching for 1.png, it would return 1 instead of the intended 3.
Back to top
View user's profile Send private message
Superfraggle



Joined: 02 Nov 2004
Posts: 753
Location: London, UK

PostPosted: Mon Apr 21, 2008 1:46 am    Post subject: Reply with quote

If you were searching for that particular file then you wouldnt use the variable A_LoopFileNameNoExt, you'd use one of the other ones :S

I myself would of found this helpful a number of times. And would like this added. I think It would be a minor change, and I might even go and try adding it myself.
_________________
Steve F AKA Superfraggle

http://r.yuwie.com/superfraggle


Last edited by Superfraggle on Mon Apr 21, 2008 1:52 am; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
corrupt



Joined: 29 Dec 2004
Posts: 2328

PostPosted: Mon Apr 21, 2008 1:51 am    Post subject: Reply with quote

instantrunoff wrote:
Are you arguing against such a file loop variable? I'm not sure I understand. If you're wondering why someone would want this, it's useful for acting upon windows that have titles that include a file's name but not its extension. The variable I'm proposing would also be useful for conversion utilities that convert one file format to another (e.g. mp3 to wav). Also, I can imagine it would be useful for file organization if you had several files corresponding to a particular project that had the same name but different types (e.g. powerpoint slide show + mp3 of speech). I've encountered all of these scenarios.
I can see a use for the information Smile but... would a large percentage of code that an average user writes using Loop, FileName require this additional information?. There are many ways to get this information if necessary ( 4 showing so far in this topic and many other possibilities)...
Back to top
View user's profile Send private message Visit poster's website
instantrunoff



Joined: 13 Jan 2008
Posts: 62

PostPosted: Mon Apr 21, 2008 1:57 am    Post subject: Reply with quote

Ian wrote:
Yes, I am arguing. If you are looping over a dir with the files:

Code:
1.txt
3.bmp
1.png


There would be confusion when searching for the file.

So if you used

Code:
Loop, *.* {
   If (A_LoopFileNameNoExt = 1) {
      MsgBox,, FileFound, The file is in posotion %A_Index%
   }
}


When searching for 1.png, it would return 1 instead of the intended 3.

But that situation & code wouldn't make sense for A_LoopFileNameNoExt*. To try to clarify, I wasn't suggesting that A_LoopFileName be removed as an available variable but just that A_LoopFileNameNoExt also be available.

[s]*Actually, it could be a good use for A_LoopFileNameNoExt, depending on your intentions by replacing "Loop, *.*" in your code with "Loop, *.png" Alternatively, if you wanted to find all files with the same name but with different extensions, A_LoopFileNameNoExt used in conjunction with A_LoopFileName would be useful, and I can't think of how that would be done without it off the top of my head.. some kind of RegExReplace I believe.[/s]

Whoops, I see what your code does, but the answer would be this:
Code:
Loop, *.* {
   If (A_LoopFileName = 1.png) {
      MsgBox,, FileFound, The file is in posotion %A_Index%
   }
}


Last edited by instantrunoff on Mon Apr 21, 2008 2:10 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
instantrunoff



Joined: 13 Jan 2008
Posts: 62

PostPosted: Mon Apr 21, 2008 2:03 am    Post subject: Reply with quote

corrupt wrote:
instantrunoff wrote:
Are you arguing against such a file loop variable? I'm not sure I understand. If you're wondering why someone would want this, it's useful for acting upon windows that have titles that include a file's name but not its extension. The variable I'm proposing would also be useful for conversion utilities that convert one file format to another (e.g. mp3 to wav). Also, I can imagine it would be useful for file organization if you had several files corresponding to a particular project that had the same name but different types (e.g. powerpoint slide show + mp3 of speech). I've encountered all of these scenarios.
I can see a use for the information Smile but... would a large percentage of code that an average user writes using Loop, FileName require this additional information?. There are many ways to get this information if necessary ( 4 showing so far in this topic and many other possibilities)...


Corrupt, I think the average user does not have your string manipulation skills. It would be a minor but useful addition, and it would be consistent with the other loop variables, which is not the case with your impressive examples.
Back to top
View user's profile Send private message Visit poster's website
instantrunoff



Joined: 13 Jan 2008
Posts: 62

PostPosted: Mon Apr 21, 2008 2:05 am    Post subject: Reply with quote

Superfraggle wrote:
If you were searching for that particular file then you wouldnt use the variable A_LoopFileNameNoExt, you'd use one of the other ones :S

I myself would of found this helpful a number of times. And would like this added. I think It would be a minor change, and I might even go and try adding it myself.


Cool! I don't know how to add things like this to AHK.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group