phpbatch-filecommand-linefsutil

Batch files - Create files based off a list


I am looking to create a large number of rather small php files based off a pre-defined list. I would also like to insert something into these .php files. I have the list ready and there are just slightly over 7500 files to create. Each line is a different PHP file, such as

Cheese.php
Cheeese.php
Cheeeese.php

You get the idea, they change slightly. The list is already in a text file and I need to read the text file line-by-line and create a file using that line. I already know the command to create files through command line is fsutil file createnew I am just looking for a way to make it do this by using the massive text file and then also add the same pre-defined text into each of the PHP files that I am creating.

Can anyone help point me in the right direction? I would do this manually but 7500 is a bit time consuming!


Solution

  • To do this in a batch-file is fairly simple:

    for /f "delims=" %%a in (phplist.txt) do (
    Echo. >> "C:\Path\To\MainDirectory\%%~a"
    ) 
    

    The above will create all the listed files blank.

    You can modify this by replacing the middle line with whatever you want and refering to the file names as %%~a.