Meeku
Meeku

Reputation: 53

PHP mkdir of a SPLFileObject

I'm trying to create n directories based on a TXT file using this code:

<?php

$file = new SPLFileObject('/Applications/MAMP/htdocs/artists_report/2014/artists.txt');
foreach ($file as $line) {
    mkdir($line);
}

?>

What I expect is mkdir assigning a namefolder based on each line I've got in artists.txt <- $line, but the directories are created without names and I can't understand why mkdir is not taking $line as a string.

Any ideas?

Upvotes: 0

Views: 804

Answers (2)

Shawn
Shawn

Reputation: 3369

<?php
$filedirectory = '/Applications/MAMP/htdocs/artists_report/2014/';
//read from your file using SPLFileObject
...some code that is setting $line with a value but converts back to a string...
//i would make $line an array or something so you can simply do:

foreach ($line AS $artist) {
    mkdir($filedirectory.$artist);
}

?>

Upvotes: 0

FuzzyTree
FuzzyTree

Reputation: 32402

Use file instead of SPLFileObject

$file = file('/Applications/MAMP/htdocs/artists_report/2014/artists.txt');
foreach ($file as $line) {
    mkdir($line);
}

This assumes that each line in artists.txt is a full path name

Upvotes: 1

Related Questions