Author Topic: IFolderCollection.Add Method  (Read 2632 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2524
  • User-Rate: +209/-0
  • Gender: Male
IFolderCollection.Add Method
« on: July 14, 2008, 12:16:22 AM »

The following example illustrates the use of the Add method to create a new folder.

JScript

Code: [Select]
function AddNewFolder(path,folderName)
{
   var fso, f, fc, nf;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f = fso.GetFolder(path);
   fc = f.SubFolders;
   if (folderName != "" )
      nf = fc.Add(folderName);
   else
      nf = fc.Add("New Folder");
}

VBScript

Code: [Select]
Sub AddNewFolder(path, folderName)
   Dim fso, f, fc, nf
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFolder(path)
   Set fc = f.SubFolders
   If folderName <> "" Then
      Set nf = fc.Add(folderName)
   Else
      Set nf = fc.Add("New Folder")
   End If
End Sub

PowerBASIC

Code: [Select]
SUB AddNewFolder (BYVAL strPath AS STRING, BYVAL strFolderName AS STRING)

   LOCAL fso AS IFileSystem
   LOCAL f AS IFolder
   LOCAL fc AS IFolderCollection
   LOCAL nf AS IFolder
   LOCAL s AS STRING

   fso = NEWCOM ("Scripting.FileSystemObject")
   f = fso.GetFolder(UCODE$(strPath))
   fc = f.SubFolders
   IF strFolderName <> "" THEN
      nf = fc.Add(UCODE$(strFolderName))
   ELSE
      nf = fc.Add(UCODE$("New Folder"))
   END IF

END SUB