Saturday, August 15, 2015

Create lots of files quickly

 on  with No comments 
In ,  
Ever needed to create a lot of files in Windows?  I was testing a security control that was supposed to monitor the filesystem for a large number of file changes in a short amount of time, a tell tale sign of some variety of ransomware.  So after quickly consulting Google, the subject matter expert of all things, I hacked together this quick one liner.  In this example, it will create 100 directories, each containing 500 files with the single word "data" in c:\temp. There's no reason why you can't nest a few more for loops to create as many levels of directories as needed.

for /l %x in (1,1,100) do ( for %y /l in (1,1,500) do (echo data > c:\temp\dir%x\file%y.txt) )

Additionally, once you have the files in place, you can change the single > to a double >> in order to add a second string "data" to the file.

For the record, the control did not work. I was able to create the files, then run the operation again to alter the files, and the operation was not stopped.
Share:

0 comments:

Post a Comment

Discuss this post!