Folder/Directory Creation Script [Updated]

Ok, have come up with a tidy little script to handle creating a file in any directory.
Input full directory including drive separated by / and this script will check and create each sub-folder/directory in turn.

function directoryCheck(inputDirectory) {
  var fso 					= new ActiveXObject("Scripting.FileSystemObject");	//--Load folder creation tools
  var directoryArray				= inputDirectory.split('/');				//--Split to drive & folders
  var directoryLength				= directoryArray.length;				//--length inc directory
  var directoryStage				= directoryArray[0]+'/';				//--Define initial path (drive)
  for (d = 0; d < directoryLength-1; d++) {								//--Loop through location array (count -1 [drive])
    var loopFolder 				= directoryArray[d+1];					//--Loop folder (+1 to skip drive)
    var directoryStage			        = directoryStage+loopFolder+'/';		        //--Stage last state + loop folder
      if (fso.FolderExists(directoryStage))								//--Does specified log year folder exisit?
      {} else {												//--Do nothing if exists	 	
      fso.CreateFolder(directoryStage);								        //--Create folder if not
      }													//--End if
  }													//--End loop

1 Like

Doesn’t file helper works?


Sorry, knew I forgot something… I searched for it but I couldn’t find it, got distracted then wrote this forgetting about the helper LOL…

1 Like