{"id":63643,"date":"2007-11-07T00:26:00","date_gmt":"2007-11-07T00:26:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2007\/11\/07\/hey-scripting-guy-how-can-i-create-a-bunch-of-wav-files-in-a-folder\/"},"modified":"2007-11-07T00:26:00","modified_gmt":"2007-11-07T00:26:00","slug":"hey-scripting-guy-how-can-i-create-a-bunch-of-wav-files-in-a-folder","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/hey-scripting-guy-how-can-i-create-a-bunch-of-wav-files-in-a-folder\/","title":{"rendered":"Hey, Scripting Guy! How Can I Create a Bunch of .WAV Files in a Folder?"},"content":{"rendered":"<p><H2><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> <\/H2>\n<P>Hey, Scripting Guy! For testing purposes I need to create a bunch of empty .WAV files in a folder. How can I write a script that will create those files for me?<BR><BR>&#8212; ZL<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, ZL. You know, yesterday was a very exciting day for the Scripting Guy who writes this column: he got to work from home, just like Scripting Guy Jean Ross does on a regular basis. (Well, OK, we\u2019re not sure that she actually <I>works<\/I> from home. But that\u2019s what she says she does.) Because the Scripting Guys are manning a booth in the Ask the Experts section at TechEd IT Forum (<A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/teched07\/itpreview.mspx\"><B>booth 22<\/B><\/A>; stop by, pick up a Fun Book, and maybe win a Dr. Scripto bobblehead doll), it was suggested that they have a cell phone so that the event organizers could reach them as needed. <\/P>\n<TABLE id=\"EFD\" class=\"dataTable\" cellSpacing=\"0\" cellPadding=\"0\">\n<THEAD><\/THEAD>\n<TBODY>\n<TR class=\"record\" vAlign=\"top\">\n<TD>\n<P class=\"lastInCell\"><B>Note<\/B> Do event organizers expect that, come 2:00 AM, one of the conference attendees might desperately need a script that can retrieve a list of processes running on a remote computer? Or maybe late one night another attendee will be unable to remember which positions the Scripting Son plays on his baseball team? (Pitcher and first base.) Well, we aren\u2019t sure. But no point in taking any chances, right? Regardless, the Scripting Guys will be on call, 24\/7.<\/P><\/TD><\/TR><\/TBODY><\/TABLE>\n<DIV class=\"dataTableBottomMargin\"><\/DIV>\n<P>Anyway, neither of the Scripting Guys has a cell phone that will work in Europe. (Which gives you an idea as to how much world traveling the Scripting Guys are typically allowed to do.) That meant they had to rent a cell phone, a phone that would be shipped to the home of the Scripting Guy who writes this column. And since <I>someone<\/I> had to be there to sign for the phone when it was delivered, well \u2026.<\/P>\n<P>So what\u2019s it like to work from home? Well, you end up sleeping in later than you normally would, then you eat breakfast and read the paper. You log on to the network, complaining all the while about how slow everything is going. You read your email, then break for lunch. And because you were reading a magazine while you were eating, you go ahead and finish the magazine once lunch is over. After lunch you\u2019re feeling restless, so you decide to knock off early, go to the gym, and get in a good 40 minutes on the exercise bike. You get home about the same time the Scripting Son does, and the two of you watch ESPN and then get ready to leave for a Husky basketball game.<\/P>\n<P>Now that we think about it, working at home isn\u2019t all that much different than working at work, at least for some us.<\/P>\n<P>Oh, wait. Due to the fact that there isn\u2019t much on TV during the day, the Scripting Guy who writes this column <I>did<\/I> manage to do one other thing while working at home. (Well, two, if you count running the dishwasher.) He also managed to write a script that can create a bunch of empty .WAV files in a folder:<\/P><PRE class=\"codeSample\">Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<\/p>\n<p>For i = 1 to 100\n    strFileName = objFSO.GetTempName\n    strFileName = Replace(strFileName, &#8220;.tmp&#8221;, &#8220;.wav&#8221;)\n    strPath = &#8220;C:\\Temp\\&#8221; &amp; strFileName\n    objFSO.CreateTextFile(strPath)\nNext\n<\/PRE>\n<P>You know, come to think of it, he did <I>three<\/I> things: he also wrote an explanation of how the script works. (No wonder he\u2019s so tired; maybe he should take tomorrow off.) We kick things off \u2013 speaking of kicking off, did we mention that the University of Washington <I>finally<\/I> won a football game last weekend, knocking off the Stanford Cardinal? Go Huskies! <\/P>\n<P>Anyway, we kick things off by creating an instance of the <B>Scripting.FileSystemObject<\/B>. What are we going to do with the FileSystemObject? You\u2019ll find out soon enough.<\/P>\n<P>And yes, that <I>is<\/I> soon enough. Trust us.<\/P>\n<P>We\u2019ve decided that, for demonstration purposes, we want to populate the folder C:\\Temp with 100 empty. WAV files. With that in mind, our next chore is to set up a For Next loop that runs from 1 to 100; that\u2019s what we do here:<\/P><PRE class=\"codeSample\">For i = 1 to 100\n<\/PRE>\n<P>When we finally get around to creating a new file, we\u2019re going to need to specify a complete path for that file, including file name. Step 1 in the process of creating that file path is to use the <B>GetTempName<\/B> method to create a random name for our file:<\/P><PRE class=\"codeSample\">strFileName = objFSO.GetTempName\n<\/PRE>\n<P>GetTempName has only one purpose in life: it generates random files names. (The \u201cTemp\u201d in GetTempName refers to the fact that these random names are often affixed to temporary files.) <\/P>\n<P>When all is said and done, GetTempName will have cranked out 100 files names similar to these:<\/P><PRE class=\"codeSample\">rad0F25C.tmp\nrad2A9FD.tmp\nradEA60F.tmp\n<\/PRE>\n<P>What\u2019s that? Hmmm, now that you mention it, those files <I>do<\/I> all have .TMP file extensions, don\u2019t they? And that\u2019s a problem; we need to have a bunch of files with a .WAV file extension.<\/P>\n<P>Fortunately for us, we included this line of code in our For Next loop:<\/P><PRE class=\"codeSample\">strFileName = Replace(strFileName, &#8220;.tmp&#8221;, &#8220;.wav&#8221;)\n<\/PRE>\n<P>What we\u2019re doing here is using VBScript\u2019s <B>Replace<\/B> function to replace any instance of the string value <I>.tmp<\/I> (which just happens to coincide nicely with the file extension for each of these files) with the string value <I>.wav<\/I>. Just like that, we\u2019ll end up with files that have names similar to <I>these<\/I>:<\/P><PRE class=\"codeSample\">rad0F25C.wav\nrad2A9FD.wav\nradEA60F.wav\n<\/PRE>\n<P>Once we have valid file names we can then use this line of code to construct the complete file path:<\/P><PRE class=\"codeSample\">strPath = &#8220;C:\\Temp\\&#8221; &amp; strFileName\n<\/PRE>\n<P>Again, there\u2019s nothing very fancy going on here. We want to create all these empty .WAV files in the folder C:\\Temp. Therefore, to construct a path for the new file we simply combine <B>C:\\Temp\\<\/B> with the name of the first file generated by GetTempName. That\u2019s going to result in the variable strPath being equal to something like this:<\/P><PRE class=\"codeSample\">C:\\Temp\\rad0F25C.wav\n<\/PRE>\n<P>If that doesn\u2019t look like a valid path, well, we don\u2019t know what does.<\/P>\n<P>Now all we have to do is call the <B>CreateTextFile<\/B> method (passing it the variable strPath) and we can create the first of our empty .WAV files:<\/P><PRE class=\"codeSample\">objFSO.CreateTextFile(strPath)\n<\/PRE>\n<P>Now, we know what you\u2019re thinking: we wanted .WAV files and yet we called the Create<I>Text<\/I>File method? What gives? <\/P>\n<P>Well, what gives is that we aren\u2019t trying to create valid .WAV files; that is, we aren\u2019t trying to create actual sound files that can be played in Windows Media Player. Instead, we\u2019re creating \u201cempty\u201d .WAV files, files that are sound files only in the sense that they have a .WAV file extension. And we can do that using the CreateTextFile method because this method doesn\u2019t care what file extension we use; after all, even actual text files don\u2019t always have a .TXT file extension. (They might be .CSV files, .XML files, .HTM files, etc.) If you need specific types of files in order to test a script (for example, you\u2019re trying to write a script that will delete only the .DOC files from a folder), well, go ahead and give CreateTextFile a file name that includes the desired file extension. CreateTextFile will take it from there.<\/P>\n<P>We hope that helps, ZL. We also hope that everyone who attends TechEd IT Forum will swing by the Ask the Experts section (<A href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/topics\/teched07\/itpreview.mspx\"><B>booth 22<\/B><\/A>) and say hi. (Well, OK. But at least drop by to pick up a Fun Book and to try your luck at winning a Dr. Scripto bobblehead.) And remember, if you need anything at all during IT Forum, any time of the day or night, just give Scripting Guy Jean Ross a call. She\u2019ll be more than happy to help you out.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! For testing purposes I need to create a bunch of empty .WAV files in a folder. How can I write a script that will create those files for me?&#8212; ZL Hey, ZL. You know, yesterday was a very exciting day for the Scripting Guy who writes this column: he got to work [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[3,4,14,5],"class_list":["post-63643","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-scripting-guy","tag-scripting-techniques","tag-text-files","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! For testing purposes I need to create a bunch of empty .WAV files in a folder. How can I write a script that will create those files for me?&#8212; ZL Hey, ZL. You know, yesterday was a very exciting day for the Scripting Guy who writes this column: he got to work [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/63643","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=63643"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/63643\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=63643"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=63643"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=63643"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}