How to rename, date/time stamp and move a file?

Hello all,

Using RS2012 R2.1:
I need to rename a text file by adding the sqlDateTime value to the end of the file name, and move it to a different folder.

I have tried this and other variations, but it does not work. The file name becomes just the last part of the time.

  Dim p As String = Path + "History\"
  Dim d As New Date
  Dim f As FolderItem = GetFolderItem(p) // + InterfaceFileName + d.SQLDateTime)
  Dim bs As  BinaryStream
  //Dim IntCmdFile As String
  
  If f = Nil Then f.CreateAsFolder
  f = GetFolderItem(p + InterfaceFileName)
  
  If f <> Nil Then 
    Dim s As string = f.Name
    s = s + "_" + d.SQLDateTime
    f.MoveFileTo
    //f.Name = s  //f.Name + d.SQLDateTime
    // f = GetFolderItem(p  + d.SQLDateTime)
    // f = GetOpenFolderItem(p  + d.SQLDateTime)
    Dim Dest As FolderItem = GetFolderItem(Path + "History\" + f.Name)
    f.CopyFileTo(Dest)
    
    
    //Dim newFolder as FolderItem
    // newFolder=destination.child(source.name)
    // newFolder.createAsFolder
    
  End If
 

The docs say this: [quote]The name of the FolderItem. Changing this name will change the name of the file or folder. [/quote]

But that does not appear to work.
Can anyone direct me to a method to do this?

Thank you!
Tim

Hi Tim

This should get you closer to what you are trying to do.

[code]
Dim p As String = Path + “History”
Dim d As New Date
// Dim f As FolderItem = GetFolderItem§ // + InterfaceFileName + d.SQLDateTime) //Don’t do this
Dim f As FolderItem = GetFolderItem(Path).Child(“History”) // + InterfaceFileName + d.SQLDateTime) //Do this instead it’s safer & xplat
Dim bs As BinaryStream
//Dim IntCmdFile As String

If f = Nil Then f.CreateAsFolder //This means that Path doesn’t exist which should be checked earlier
// Create the History folder if necessary
If Not f.exists Then
f.CreateAsFolder
End If
// f = GetFolderItem(p + InterfaceFileName) // This appears to be trying to get your source file in the history folder
f = GetFolderItem(path).Child(InterfaceFileName) //This is probably what you want to do

If f <> Nil Then
Dim s As string = f.Name
s = s + “_” + d.SQLDateTime
// f.MoveFileTo //This requires a destination
//f.Name = s //f.Name + d.SQLDateTime
// f = GetFolderItem(p + d.SQLDateTime)
// f = GetOpenFolderItem(p + d.SQLDateTime)
// Dim Dest As FolderItem = GetFolderItem(Path + “History” + f.Name) // Again don’t do it this way
Dim Dest As FolderItem = GetfolderItem(Path).Child(“History”).Child(s) //Get’s your destination
f.MoveFileTo Dest //Moves the file
// f.CopyFileTo(Dest) This will now fail due to f not existing

//Dim newFolder as FolderItem
// newFolder=destination.child(source.name)
// newFolder.createAsFolder

End If[/code]

HTH

Wayne

Hi Wayne!
Thank you for your response. I thought I had replied already thanking you, but apparantly had not. Again, thank you for the details and help!
Tim

Hi Tim

You are welcome!