decci
decci

Reputation: 1

DOS Batch Creating files with subfolders after reading from a list

I have a txt file which has a list of filenames with directory structure. Example below (w/o the blank lines in between):

C:\createdocs\1.txt
C:\createdocs\2.txt
C:\createdocs\mydocs\3.txt
C:\createdocs\mysubdocs\4.txt
C:\createdocs\5.txt

I want to create a batch file which will read from this file one by one and will create the file with some dummy value ("this is a test file") at the path provided at each line. If the directory doesn't exist, create the directory as well. Is it possible using the batch scripts?

Upvotes: 0

Views: 741

Answers (1)

Marc B
Marc B

Reputation: 360742

In a cmd shell, you can use for /f %var in (file.txt) to process each line of the file sequentially. Then use the stuff detailed in this answer to process each line you've retrieved to extract the path. Then it's a simple matter of doing a mkdir followed by echo 'this is a dummy file' > thefile

Upvotes: 1

Related Questions