supposed there is a folder named example
, and in it there are some csv file eg(a.csv, b.csv....
).
the test.php
directory is the same as example
folder. now i want to pass all the csv file name to the following if condition. namely, replace test.csv
with all the csv file name
if (($handle = fopen("test.csv", "r"))
how do i do?
i using the following code:
$files= glob("./example/*.csv");
if (($handle = fopen("$files", "r"))
but it doesn't work. thank you.
Method 1: Using Glob module glob(path). This returns all the CSV files' list located within the path. The regex used is equivalent to *. csv, which matches all files for an extension .
In order to read multiple CSV files or all files from a folder in R, use data. table package. data. table is a third-party library hence, in order to use data.
To get a list of all the files and folders in a particular directory in the filesystem, use os. listdir() in legacy versions of Python or os. scandir() in Python 3.
$files
is an array, you need to loop with it.
$files = glob("./example/*.csv");
foreach($files as $filepath) {
if ($handle = fopen($filepath, "r")) {
// ...
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With