jaberwacky Posted August 7, 2010 Share Posted August 7, 2010 (edited) If you ever find yourself in need of a dummy file for testing then this function may be what you need. Feed the function a size in megabytes and give it a location to store the dummy file and you're done. Large files may take a while depending on your system. [update: April 28, 2011] -- Now you can create UNICODE files! expandcollapse popup#include-once Func DummyFile_Create( Const $iTotalB , Const $fileSaveLoc , Const $alphaNumeric = 1 ) Local $string Local Const $mode = 2 + 8 Local Const $binary = 16 Local Const $utf16 = 32 Switch $alphaNumeric Case 0 ; numeric data FileOpen( $fileSaveLoc , $mode ) If @error = -1 Then Return SetError( 1 , 0 , 1 ) For $i = 1 To $iTotalB $string &= Random( 0 , 9 , 1 ) Next FileWrite( 1 , $string ) Case 1 ; ASCII alphanumeric data FileOpen( $fileSaveLoc , $mode ) If @error = -1 Then SetError( 1 , 0 , 1 ) For $i = 1 To $iTotalB $string &= Chr( Random( 0 , 255 , 1 ) ) Next FileWrite( 1 , $string ) Case 2 ; dummy file with no data ; trancexx FileOpen( $fileSaveLoc , $mode + $binary ) If @error = -1 Then SetError( 1 , 0 , 1 ) FileSetPos( 1 , $iTotalB - 1 , 0 ) FileWrite( 1 , Chr( 32 ) ) ; Chr( 32 ) = NUL Case 3 ; UNICODE data FileOpen( $fileSaveLoc , $mode + $utf16 ) If @error = -1 Then SetError( 1 , 0 , 1 ) For $i = 1 To $iTotalB $string &= ChrW( Random( 256 , 65535 , 1 ) ) Next FileWrite( 1 , $string ) EndSwitch FileClose( 1 ) EndFunc Edited May 2, 2011 by LaCastiglione Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
FuryCell Posted August 7, 2010 Share Posted August 7, 2010 Why the 1028 instead of 1024? HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
jaberwacky Posted August 7, 2010 Author Share Posted August 7, 2010 lulz, that's why it wasn't coming out right, sheesh. Thanks FuryCell! Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Ascend4nt Posted August 7, 2010 Share Posted August 7, 2010 If you just need a dummy file, period (without random #'s), you could easily quicken the routine by using a DLLStruct: Func _FileCreateDummyInMB($sFilename,$iTotalMB) Local $stData=DllStructCreate("byte[1048576]"),$binData=DllStructGetData($stData,1) Local $hFile=FileOpen($sFilename,2) For $i=1 To $iTotalMB FileWrite($hFile,$binData) Next FileClose($hFile) EndFunc _FileCreateDummyInMB(@DesktopDir&"\dummyfile.bin",10) My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs |Â Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) |Â Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
trancexx Posted August 7, 2010 Share Posted August 7, 2010 Or something like this: Func _FileCreateDummyInMB($sFilename, $iTotalMB) Local $hFile = FileOpen($sFilename, 18) FileSetPos($hFile, $iTotalMB * 1048576 - 4, 0) FileWrite($hFile, 0) FileClose($hFile) EndFunc ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Ascend4nt Posted August 8, 2010 Share Posted August 8, 2010 Very clever, trancexx. I didn't know you could set a position on a newly created file that is past the current position. Good to know My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs |Â Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) |Â Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
jaberwacky Posted August 8, 2010 Author Share Posted August 8, 2010 (edited) Hmmm, what I use one of the two methods posted above to create a file of predetermined size. Then create a huge string that would fit snug into the file and just write it all at once? Edited August 8, 2010 by jaberwocky6669 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
FuryCell Posted August 8, 2010 Share Posted August 8, 2010 Hmmm, what I use one of the two methods posted above to create a file of predetermined size. Then create a huge string that would fit snug into the file and just write it all at once?Depending on your definition of 'Huge' RAM usage might go through the roof. HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
jaberwacky Posted August 8, 2010 Author Share Posted August 8, 2010 I always forget to take that into account. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now