| View previous topic :: View next topic |
| Author |
Message |
instantrunoff
Joined: 13 Jan 2008 Posts: 62
|
Posted: Mon Apr 21, 2008 12:23 am Post subject: New Built-In File Loop Variable: A_LoopFileNameNoExt |
|
|
| For specifying a file's name without its extension within a file-loop. |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2328
|
Posted: Mon Apr 21, 2008 12:53 am Post subject: |
|
|
| 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 |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 62
|
Posted: Mon Apr 21, 2008 1:00 am Post subject: |
|
|
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 |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2328
|
Posted: Mon Apr 21, 2008 1:00 am Post subject: |
|
|
another... | Code: | | OutputVar := SubStr(A_LoopFileName, 1, StrLen(A_LoopFileName) - ((A_LoopFileExt <> "") ? (StrLen(A_LoopFileExt) + 1) : 0)) |
|
|
| Back to top |
|
 |
Ian
Joined: 15 Jul 2007 Posts: 1077 Location: Enterprise, Alabama
|
Posted: Mon Apr 21, 2008 1:16 am Post subject: |
|
|
| There would be confusion between files with the same names. |
|
| Back to top |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 62
|
Posted: Mon Apr 21, 2008 1:18 am Post subject: |
|
|
| Ian wrote: | | There would be confusion between files with the same names. |
I don't understand what you mean. |
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2328
|
Posted: Mon Apr 21, 2008 1:18 am Post subject: |
|
|
another... | Code: | | OutputVar := RegExMatch(A_LoopFileName, "(.*)\.(.*)$", SubPat) ? SubPat1 : A_LoopFIleName |
|
|
| Back to top |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2328
|
Posted: Mon Apr 21, 2008 1:19 am Post subject: |
|
|
| 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 |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 62
|
Posted: Mon Apr 21, 2008 1:25 am Post subject: |
|
|
| 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 |
|
 |
Ian
Joined: 15 Jul 2007 Posts: 1077 Location: Enterprise, Alabama
|
Posted: Mon Apr 21, 2008 1:43 am Post subject: |
|
|
Yes, I am arguing. If you are looping over a dir with the files:
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 |
|
 |
Superfraggle
Joined: 02 Nov 2004 Posts: 753 Location: London, UK
|
Posted: Mon Apr 21, 2008 1:46 am Post subject: |
|
|
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 |
|
 |
corrupt
Joined: 29 Dec 2004 Posts: 2328
|
Posted: Mon Apr 21, 2008 1:51 am Post subject: |
|
|
| 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 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 |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 62
|
Posted: Mon Apr 21, 2008 1:57 am Post subject: |
|
|
| Ian wrote: | Yes, I am arguing. If you are looping over a dir with the files:
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 |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 62
|
Posted: Mon Apr 21, 2008 2:03 am Post subject: |
|
|
| 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 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 |
|
 |
instantrunoff
Joined: 13 Jan 2008 Posts: 62
|
Posted: Mon Apr 21, 2008 2:05 am Post subject: |
|
|
| 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 |
|
 |
|