1 out of 1 rated this helpful - Rate this topic

Name Property (FileSystemObject)

Sets or returns the name of a specified file or folder. Read/write.

object.Name [= newname] 
object

Required. Always the name of a File or Folder object.

newname

Optional. If provided, newname is the new name of the specified object.

The following code illustrates the use of the Name property:

function ShowFileAccessInfo(filespec)
{
   var fso, f, s;
   fso = new ActiveXObject("Scripting.FileSystemObject");
   f = fso.GetFile(filespec);
   s = f.Name + " on Drive " + f.Drive + "<br>";
   s += "Created: " + f.DateCreated + "<br>";
   s += "Last Accessed: " + f.DateLastAccessed + "<br>";
   s += "Last Modified: " + f.DateLastModified;
   return(s);
}

Function ShowFileAccessInfo(filespec)
   Dim fso, f, s
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFile(filespec)
   s = f.Name & " on Drive " & UCase(f.Drive) & "<BR>"
   s = s & "Created: " & f.DateCreated & "<BR>"
   s = s & "Last Accessed: " & f.DateLastAccessed & "<BR>"
   s = s & "Last Modified: " & f.DateLastModified   
   ShowFileAccessInfo = s
End Function

Applies To:

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Sample with [= newname] argument (incorporates GetTempName Method)
Sub RenameFile(filespec,newfilename)
   Dim fso, f
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.GetFile(filespec)
   tempfilename = fso.GetTempName
   f.Name = tempfilename
  f.Name = newfilename
End Sub
Rename xyz.JPG -> xyz.jpg dont work

An error occurs if the newname argument only changes capitalization of the file extension. This can be prevented by renaming the file to a unique temporary filename, then to the final newname.  For example:

item.Name = "a" & newName
item.Name = newName

Note that just appending a letter to the name could still cause a collision with an existing file name. 
Use the GetTempName Method to avoid this problem.

http://msdn.microsoft.com/en-us/library/w0azsy9b(v=VS.85).aspx 
please elaborate on use of "newname"
Not so useful: "Optional. If provided, newname is the new name of the specified object."
Then in the examples this param is not used.

Can somebody please elaborate on the usage and also provide an example. This does not let me rename a file as far as I can tell, so what it is actually used for?