• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 52
  • Last Modified:

Creating Folder & Renaming it with today’s date


I am trying to create a script that can create a folder and then it renamed as today’s date..

Folder: 22/04/2018
Nick Collins
Nick Collins
1 Solution
Bill PrewCommented:
Will the parent folder already exist that the new one will be created in?

Nick CollinsAuthor Commented:
Fernando SotoRetiredCommented:
Hi Nick;

You can not use that format because you have a couple characters that are reserved
Naming Conventions
The following fundamental rules enable applications to create and process valid names for files and directories, regardless of the file system:
  • Use a period to separate the base file name from the extension in the name of a directory or file.
  • Use a backslash (\) to separate the components of a path. The backslash divides the file name from the path to it, and one directory name from another directory name in a path. You cannot use a backslash in the name for the actual file or directory because it is a reserved character that separates the names into components.
  • Use a backslash as required as part of volume names, for example, the "C:\" in "C:\path\file" or the "\\server\share" in "\\server\share\path\file" for Universal Naming Convention (UNC) names. For more information about UNC names, see the Maximum Path Length Limitation section.
  • Do not assume case sensitivity. For example, consider the names OSCAR, Oscar, and oscar to be the same, even though some file systems (such as a POSIX-compliant file system) may consider them as different. Note that NTFS supports POSIX semantics for case sensitivity but this is not the default behavior. For more information, see CreateFile.
  • Volume designators (drive letters) are similarly case-insensitive. For example, "D:\" and "d:\" refer to the same volume.
  • Use any character in the current code page for a name, including Unicode characters and characters in the extended character set (128–255), except for the following:
The following reserved characters:
  • < (less than)
  • > (greater than)
  • : (colon)
  • " (double quote)
  • / (forward slash)
  • \ (backslash)
  • | (vertical bar or pipe)
  • ? (question mark)
  • * (asterisk)
Integer value zero, sometimes referred to as the ASCII NUL character.
Characters whose integer representations are in the range from 1 through 31, except for alternate data streams where these characters are allowed. For more information about file streams, see File Streams.
Any other character that the target file system does not allow.
Use a period as a directory component in a path to represent the current directory, for example ".\temp.txt". For more information, see Paths.
Use two consecutive periods (..) as a directory component in a path to represent the parent of the current directory, for example "..\temp.txt". For more information, see Paths.
Do not use the following reserved names for the name of a file:
CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed immediately by an extension; for example, NUL.txt is not recommended. For more information, see Namespaces.
Do not end a file or directory name with a space or a period. Although the underlying file system may support such names, the Windows shell and user interface does not. However, it is acceptable to specify a period as the first character of a name. For example, ".temp".
Bill PrewCommented:
Assuming you want a VBScript solution, here is the basic idea.  I used a stamp of YYYYMMDD for the created folder, adjust as needed.

Option Explicit

' Define used variables
Dim objFSO, strDateStamp, strBaseDir

' Specify Base folder path (MUST EXIST ALREADY!)
strBaseDir = "c:\temp\basedir"

' Create file system object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

' Build date stamp in YYYYMMDD format
strDateStamp = Year(Now) & Right("0" & Month(Now), 2) & Right("0" & Day(Now), 2)

' Now create desired folder
objFSO.CreateFolder(strBaseDir & "\" & strDateStamp)

Open in new window

used a stamp of YYYYMMDD

I'd support this, for two reasons:

The DDMMYYYY format (used in the UK), could be confusing to others (e.g. USA) with values such as 11041978.
The YYYYMMDD format (the international date format) has the major advantage that the names are automatically sorted, which is not true of the other two formats mentioned.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now