Q. Generate random files in Windows. Let the random files / directories generated have compression or encryption attribute set randomly. Also the files as well as directories should have the alternate data streams (ADS) associated with. There should be provision of updating certain parts of this randomly generated data. This kind of utility is very useful to test file system backup products.
Ans: For long time I was searching for the Unix like “dd” command line utility for Windows. I came across this utility: Random Data File Creator (RDFC). This gives us “dd” kind of functionality. Download this utility and keep it in your C:\
Use below batch script to generate random files and directories with compression / encryption attributes and alternate data streams associated with them.
echo off set testname=%0 set foldername=%1 set fext=%2 set size=%3 set unit=%4 set no=%5 set outerfolder=%6 set innerfolder=%7 set /A filenumber = 1 set dest=%foldername% set str=%dest: =% mkdir %str% set /A a=0 :Loop1 set dest1=%str%\%a% set str1=%dest1: =% mkdir %str1% set /A b=0 :Loop2 set dest2=%str1%\%b% set str2=%dest2: =% mkdir %str2% set /A c=0 :Loop3 set fname=%str2%\file-%filenumber%.%fext% set tmpfname=%str2%\file_tmp c:\rdfc.exe %tmpfname% %size% %unit% overwrite type nul >> %fname% :: append data to existing file type %tmpfname% >> %fname% :: create alternate data stream set /A adsproperty = %filenumber% %% 2 IF %adsproperty%==1 (type %tmpfname% >> %fname%:my_file_ads) del %tmpfname% set /A filenumber = %filenumber% + 1 set /A c=%c%+1 IF %c%==%no% (goto end3) ELSE (goto loop3) :end3 rem ******************* :: set compression / encryption attribute set /A dirproperty = %b% %% 3 IF %dirproperty%==1 (compact /C /S:%str2%) IF %dirproperty%==2 (cipher /E /S:%str2%) set tmpfname=%str1%\file_tmp c:\rdfc.exe %tmpfname% %size% %unit% overwrite set /A adsproperty = %b% %% 2 IF %adsproperty%==1 (type %tmpfname% >> %str2%:my_dir_ads) del %tmpfname% set /A b=%b%+1 IF %b%==%innerfolder% (goto end2) ELSE (goto loop2) :end2 rem ******************* set /A a=%a%+1 IF %a%==%outerfolder% (goto end1) ELSE (goto loop1) :end1 :: usage random_files.bat foldername EXTENTION SIZE UNIT[B|kB|MB|GB] NO_OF_FILES no_outerfolders no_innerfolders
C:\>random_files.bat D:\test bin 1 kB 2 3 3
This will generate D:\test folder. Inside this folder there will be 3 subfolders created numbered: 0, 1, 2. Inside each of these folders again there will be three subfolders numbered 0, 1, 2. Inside each of these folders there will be 2 random 1 KB files with .bin extension are created. Starting from the folder named 1, each of the third inner folder and its contents will be compressed. Starting from inner folder numbered 2, each of the third folder and its contents will be encrypted. Each of the second file created will have an alternate data stream (ADS) associated with it. Each of the second inner folder created will have alternate data stream (ADS) associated with it.
C:\>random_files.bat D:\test bin 512 B 4 3 1
Running this command for the second time only updates first two files in the 0’th inner folder in all the three outer folders. Now those first two files will have size 1.5 kB. (The new data is appended). Apart from this two new files of size 512 bytes are also created in each of the 0’th inner folder.
You can have any permutation to generate random data and keep on updating that data with any combination 🙂