Loop all CSV files in a folder the read each files

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
jmozzart
Posts: 2
Joined: 26 May 2022, 23:44

Loop all CSV files in a folder the read each files

Post by jmozzart » 26 May 2022, 23:54

I want to process all CSV files in a certain folder then loop it again to read each CSV files (or make action with it). But this script below don't work.

Code: Select all

Sleep 1000
Loop Files, C:\Users\elnicx\OneDrive\Desktop\ProductDBAuto\reviews\*.csv
{

	Loop, parse, read, C:\Users\elnicx\OneDrive\Desktop\ProductDBAuto\reviews\%A_LoopFileFullPath%.csv
	
	{
	
	Column1 := StrSplit(A_LoopReadLine, ",").1
	Column2 := StrSplit(A_LoopReadLine, ",").2
	Column3 := StrSplit(A_LoopReadLine, ",").3

	MsgBox, 4, , %Column1% - %Column2% - %Column3%
	
	IfMsgBox, No
	break
	
	}
}

return

Hope someone could help. Thanks.

User avatar
boiler
Posts: 16772
Joined: 21 Dec 2014, 02:44

Re: Loop all CSV files in a folder the read each files

Post by boiler » 27 May 2022, 00:43

This line has a couple big problems:

Code: Select all

	Loop, parse, read, C:\Users\elnicx\OneDrive\Desktop\ProductDBAuto\reviews\%A_LoopFileFullPath%.csv
There is no such thing as Loop, Parse, Read. What you need to do first is read the file contents into a variable using FileRead. Then you would parse them if that’s what you want to do.

This doesn’t make sense as a file path:
C:\Users\elnicx\OneDrive\Desktop\ProductDBAuto\reviews\%A_LoopFileFullPath%.csv

A_LoopFileFullPath is already a full path to the file (hence the name) including the full directory path and the .csv extension. So you just tacked on the path to the beginning and you tacked on the extension to the end of a file path that already included both of those things.

Depending on what’s inside your .csv files, you would then parse it on the line feeds to break it up into individual lines, then you can split it by the commas if you want, although it’s safer to use another parsing loop that uses “CSV” as the parsing criterion.

jmozzart
Posts: 2
Joined: 26 May 2022, 23:44

Re: Loop all CSV files in a folder the read each files

Post by jmozzart » 27 May 2022, 03:50

I solved it earlier. That is the problem. I shouldn't include the directory when it is already declared in A_LoopFileFullPath.
Parse isn't included in the original script. I forgot to remove it.

Post Reply

Return to “Ask for Help (v1)”