如何在PHP中创建文件夹 - 存储在数组中的文件夹的名称?

时间:2016-12-18 14:47:24

标签: php directory mkdir

我有以下代码。如果尚未创建文件夹,我想创建它们。我能以更优雅的方式做到吗?更有活力?我可以用这种方式调用mkdir()吗?

private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
            if (e.KeyCode == Keys.Enter)
            {
                e.SuppressKeyPress = true;
                int iColumn = dataGridView1.CurrentCell.ColumnIndex;
                int iRow = dataGridView1.CurrentCell.RowIndex;
                if (iColumn == dataGridView1.Columns.Count - 1)
                    dataGridView1.CurrentCell = dataGridView1[0, iRow + 1];
                else
                    dataGridView1.CurrentCell = dataGridView1[iColumn + 1, iRow];
            }
            } 
            catch { }
        }
        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        { 
            if (e.ColumnIndex == dataGridView1.Columns.Count - 1)
            {
                dataGridView1.CurrentCell = dataGridView1.Rows[dataGridView1.CurrentRow.Index + 1].Cells[0];
            }
            else
            {
                SendKeys.Send("{UP}");
                SendKeys.Send("{left}");
            }

        }

感谢。

$array = array('Stylesheets' => 'css', 'Javascript' => 'js') //ETC
    mkdir($array, 0777, true);

创建目录:

<?php
header('Content-Type: text/html; charset=utf-8'); 
?>

1 个答案:

答案 0 :(得分:3)

循环遍历数组以动态创建目录,如下所示:

$array = array('Stylesheets' => 'css', 'Javascript' => 'js');

foreach($array as $dir){
    if ( !file_exists($dir) ) {
        mkdir($dir, 0777, true) ;
        echo $dir . ' directory has been created.';
    }
}