Jump to content

Date as the name of the file

- - - - -

  • Please log in to reply
3 replies to this topic

#1
Francist

Francist

    Newbie

  • Members
  • PipPip
  • 26 posts
Hi

I need to make a program that renames a file to the date.

I'm using the command My.Computer.FileSystem.RenameFile("FILE LOCATION", "DESIRED FILENAME")

I've tryed using My.Computer.Clock.LocalTime though I get the error "Argument 'newName' must be a name, and not a relative or absolute path: '23/12/2011 13:18:50'."

Has anyone done this before?

Francis.

EDIT - I think the problem is that windows does not allow characters such as "/" and ":" meaning that a different command will have to be used. Does anyone know any?

#2
lespauled

lespauled

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 232 posts
  • Programming Language:C, C++, C#, JavaScript, PL/SQL, Delphi/Object Pascal, Visual Basic .NET, Pascal, Transact-SQL, Bash
Try something like yourDate.ToString("yyyyMMddhhmmss")

#3
Blimp

Blimp

    Programmer

  • Members
  • PipPipPipPip
  • 154 posts
The problem here is with the
23/12/2011
The "/" is an invalid character. As you can see, windows will think that you are telling it to access another directory, rather than renaming the file in that folder.

#4
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 856 posts
  • Location:Arkansas
Use the String.Replace() method to change the '/' characters into '-' characters.

Documentation:
String.Replace Method (Char, Char)
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users