Loop Files not working Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Gate
Posts: 27
Joined: 31 Jan 2021, 20:00

Loop Files not working

28 Nov 2021, 15:40

Code: Select all

d := "C:\Users\" A_UserName "\Downloads"
Loop, Files, % d
	msgbox % A_loopfilename
For some weird reason, this program doesn't work. I've been staring at it for a while and comparing it to the help docs and I really think it should work.
My downloads folder is filled with .txt files.
When debugged, the program goes to line 2 and then never hits line 3.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: Loop Files not working

28 Nov 2021, 15:43

try

Code: Select all

d := "C:\Users\" A_UserName "\Downloads\*.txt"
Gate
Posts: 27
Joined: 31 Jan 2021, 20:00

Re: Loop Files not working

28 Nov 2021, 15:49

Xtra wrote:
28 Nov 2021, 15:43
try

Code: Select all

d := "C:\Users\" A_UserName "\Downloads\*.txt"
This also did the same thing as my original code. Thank you for your idea though!
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Loop Files not working

28 Nov 2021, 15:51

Code: Select all

d := StrReplace(A_Desktop, "Desktop", "Downloads\*.txt")
Loop, Files, % d
 MsgBox, %A_LoopFileName%
gregster
Posts: 9000
Joined: 30 Sep 2013, 06:48

Re: Loop Files not working

28 Nov 2021, 15:55

Gate wrote:
28 Nov 2021, 15:49
Xtra wrote:
28 Nov 2021, 15:43
try

Code: Select all

d := "C:\Users\" A_UserName "\Downloads\*.txt"
This also did the same thing as my original code. Thank you for your idea though!
It actually does something else, afaics. Your original code only looks for a file called Downloads.
Xtra's approach works for me.

You could check if A_UserName is correct in your case, and leads you to the correct Downloads folder.
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Loop Files not working

28 Nov 2021, 15:56

My script explained: there are situations where the user's directory name differs from the user's login name.
Gate
Posts: 27
Joined: 31 Jan 2021, 20:00

Re: Loop Files not working

28 Nov 2021, 16:08

I tried everyone's suggestions above, thanks. They don't work for some reason.

I think the issue is that I'm using a virtual machine. I'm not sure how to loop through files using remote desktop. I'm trying to loop through the files on the remote desktop from the remote desktop. But it seems AHK can't pick them up with this command. [EDIT: this was a wrong assumption, AHK could pick them up]
Last edited by Gate on 28 Nov 2021, 16:22, edited 1 time in total.
User avatar
mikeyww
Posts: 26877
Joined: 09 Sep 2014, 18:38

Re: Loop Files not working  Topic is solved

28 Nov 2021, 16:09

If my script failed, then you can add a line that displays the value of your directory variable, and then displays the entire directory contents.

Code: Select all

d := StrReplace(A_Desktop, "Desktop", "Downloads")
MsgBox, 64, Directory, %d%
Loop, Files, % d "\*.txt"
 MsgBox, %A_LoopFileName%
Run, %ComSpec% /k DIR "%d%"
Gate
Posts: 27
Joined: 31 Jan 2021, 20:00

Re: Loop Files not working

28 Nov 2021, 16:21

Wow - this is embarrassing haha. My downloads folder was filled with csv files but they all had the notepad icon and I assumed they were txt files. Everyone's code works other than my original code.

That last bit of code you posted was useful because I saw all the filenames.

Thank you
RussF
Posts: 1264
Joined: 05 Aug 2021, 06:36

Re: Loop Files not working

28 Nov 2021, 16:26

Windows File explorer -> View, check the box next to "File name extensions". :)

Russ

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, mcd, mikeyww, Nerafius and 126 guests