Skip to content

Instantly share code, notes, and snippets.

@sqe
Last active February 14, 2023 21:15
Show Gist options
  • Save sqe/7eb1641edf1eba4eadde to your computer and use it in GitHub Desktop.
Save sqe/7eb1641edf1eba4eadde to your computer and use it in GitHub Desktop.
test data generator
import os
# Please change per your desire:
Source_File_Name = str(raw_input("input the text file name: "))
Destination = str(raw_input("input the destination directory: ")) #c:\\Python27\\Test_Data"
Word_Count = int(raw_input("how many words should be read into each file: ")) # 10
How_Many_Files = int(raw_input("how many files you want to generate: ")) #100
Dir_Divider = int(raw_input("how many files per directory: ")) #25
Destination_File_Prefix = str(raw_input("input future file prefix: ")) #"WaP_"
Destination_File_Extention = str(raw_input("input future file's extension: ")) #".txt"
# Do not change these:
Start_Index = 0
File_Count = 0
Destination_Part = Destination + '0000'
Source_File = open(Source_File_Name,'r')
List_Of_Words = Source_File.read().split()
Words_In_Source_File = len(List_Of_Words)
while File_Count < How_Many_Files:
Start_Index = (Start_Index + Word_Count) % Words_In_Source_File
Selected_Words = " ".join(List_Of_Words[Start_Index:Start_Index + Word_Count:1])
File_Count = File_Count + 1
File_Name = Destination_File_Prefix + str(File_Count) + Destination_File_Extention
File_Object = open(Destination_Part + "\\" + File_Name,'w')
File_Object.write(Selected_Words + '\r\nFILEID ' + str(File_Count))
File_Object.close()
if File_Count % int(Dir_Divider) is 0:
Destination_Part = Destination + "\\" + str(Dir_Divider)
os.mkdir(Destination_Part)
Dir_Divider += 25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment