

' End of FileSystemObject example: NewFile VBScript Wscript.Echo "Just created " & strDirectory & strFile Set objFile = objFSO.CreateTextFile(strDirectory & strFile) 'Creates the file using the value of strFile on Line 11 Set objFolder = objFSO.CreateFolder(strDirectory) ' Create the Folder specified by strDirectory on line 10 Set objFSO = CreateObject("Scripting.FileSystemObject") ' -'ĭim objFSO, objFSOText, objFolder, objFile ' Sample VBScript to create a file using FileSystemObject Sample VBScript to Create a File ' NewFile.vbs


Should you get permission errors, I recommend that you logon as administrator. This is a script that will create a file equally well on a Windows server or an XP machine. To tell the whole truth, I fervently believe that you learn more when scripts go wrong – providing you can fix the error quickly. I admit this is poor scripting, but my dilemma is keeping it simple and highlighting the learning steps, versus a slick script that is difficult to follow. To cure the problem, move on to the second script. The cost of focussing on one method is that Example 1 works fine the first time you execute the script, but if you run it a second time you get an error. The idea behind this script is to highlight the code need to create a file. Example 1 – Basic VBScript to Create a File with CreateTextFile Naturally, we need a folder to hold our file, therefore, our script will test to see if the folder exists, and if not, then our code will create a folder. Our mission on this page is clear, to create a file.
