How to create and name a file/folder based on current timestamp
If you are looking for a way to automatically create and name files and folders based on system timestamps, you have come to the right place. There is a super simple way to accomplish this task. The created folders or files can then be used for various purposes such as storing file backups, sorting files based on date, etc.
In this article, we will explain how to automatically create files and folders in Windows 11/10 and name them based on the system’s timestamp in some very simple steps. The method used is a batch script, which is very simple. Hope you enjoyed reading this article.
Section 1: How to automatically create and name a folder based on the current timestamp of the system
Step 1: First, Navigate to the parent folder where you want to create the folder and name it based on the system's current timestamp.
Next, right-click the empty area, click New, and then click the Text Document option.
Step 2: Nowdouble-clickthe newly created text document to edit it.
Step 3: After opening the text document in Notepad, copy and paste the following script onto it.
回声设置 CUR_YYYY=%date:~10,4%设置 CUR_MM=%date:~4,2%设置 CUR_DD=%date:~7,2%设置 CUR_HH=%time:~0,2%如果 %CUR_HH% lss 10(设置 CUR_HH=0%time:~1,1%)设置 CUR_NN=%time:~3,2%设置 CUR_SS=%time:~6,2%设置 CUR_MS=%time:~9,2%设置 SUBFILENAME=%CUR_DD%-%CUR_MM%-%CUR_YYYY%_%CUR_HH%.%CUR_NN%.%CUR_SS%mkdir %SUBFILENAME%
Don’t forget to press the CTRL S key at the same time to save the file.
Script description
This script firstextracts the current day, month, year, hour, Minutes, seconds and milliseconds. The script responsible for this part is as follows.
设置CUR_YYYY =%date:~10,4%设置CUR_MM =%date:~4,2%设置CUR_DD =%date:~7,2%设置CUR_HH =%time:~0,2%如果 %CUR_HH% lss 10(设置 CUR_HH=0%time:~1,1%)设置CUR_NN =%time:~3,2%设置CUR_SS =%time:~6,2%设置CUR_MS =%time:~9,2%
CUR_YYYY – Store the year CUR_MM – Store the month CUR_DD – Store the day CUR_HH – Storage hours CUR_NN – Storage minutes CUR_SS – Storage seconds CUR_MS – Storage millisecondsThe following lines are The line responsible for formatting the folder name. Based on the following lines, the name of the folder will be in the format
Day-Month-Year_Hours.Minutes.Seconds. The format is then saved in a variable named SUBFILENAME.
设置 SUBFILENAME=%CUR_DD%-%CUR_MM%-%CUR_YYYY%_%CUR_HH%.%CUR_NN%.%CUR_SS%
Finally, use the mkdir command to create the folder.
mkdir %SUBFILENAME%
How to adjust the naming format
- If you need another format for naming your folders, you can use the variables explained in the section above. For example, if you want the folder names to be formatted like Year_Month_Day-Seconds.Hours.Minutes, then the SUBFILENAME line of your
- settings will have to be changed as follows.
设置 SUBFILENAME=%CUR_YYYY%-%CUR_MM%-%CUR_DD%_%CUR_SS%.%CUR_HH%.%CUR_NN%
Copy after loginResults ==>
You can also change the separator between variables. For example, if you want the
- hyphen
- to also be used to separate times instead of the dot, then your SUBFILENAME must be changed to the following.
设置 SUBFILENAME=%CUR_DD%-%CUR_MM%-%CUR_YYYY%_%CUR_HH%-%CUR_NN%-%CUR_SS%
Copy after loginResult==>
- If you want the Date
- element and TimeWithout separators between elements, but requiring a hyphen between date and time, SUBFILENAME would be:
设置 SUBFILENAME=%CUR_DD%%CUR_MM%%CUR_YYYY%_%CUR_HH%%CUR_NN%%CUR_SS%
Copy after loginResult==>
Step 4
: Next, go back to the folder where you saved the text document, click it and press F2 Keyrenameit. Provide a name of your choice, but you must specify the
extensionas bat. This is the most important part.
: After renaming and clicking elsewhere, you will see the Rename Confirmation dialog box. Click the Yes button to proceed to the next step.
: Your batch script is now ready to execute. Double-click the file to execute it.
第7步:魔术!将在与批处理脚本相同的文件夹内创建一个新文件夹,其命名基于系统的当前时间戳。
第 2 节:如何根据系统的当前时间戳自动创建文件并命名
在第 1 节中,我们创建了一个基于系统当前时间戳命名的文件夹。在本节中,让我们看看如何根据系统当前的时间戳自动创建文件并为其命名。
首先,创建第 1 节中详述的批处理文件。
第 1 步:右键单击您从第 1 节创建的批处理文件,然后单击显示更多选项。
第 2 步:从展开的菜单中,单击“编辑”选项。
第 3 步:现在,注释掉最后的mkdir 行。这是负责制作文件夹的脚本部分。
要在批处理脚本中注释掉 一行,您需要在该行的开头添加2 个冒号。这将使脚本忽略冒号后面的行。因此,您的 mkdir 行将如下所示,并且在脚本执行期间将被忽略。
::mkdir %SUBFILENAME%
现在,让我们使用相同的命名格式添加将创建文件的行。
echo "你好,欢迎来到极客页面" > %SUBFILENAME%.txt
因此,需要出现在批处理脚本文件中的最终代码应如下所示。
回声设置 CUR_YYYY=%date:~10,4%设置 CUR_MM=%date:~4,2%设置 CUR_DD=%date:~7,2%设置 CUR_HH=%time:~0,2%如果 %CUR_HH% lss 10(设置 CUR_HH=0%time:~1,1%)设置 CUR_NN=%time:~3,2%设置 CUR_SS=%time:~6,2%设置 CUR_MS=%time:~9,2%设置 SUBFILENAME=%CUR_DD%%CUR_MM%%CUR_YYYY%_%CUR_HH%%CUR_NN%%CUR_SS%::mkdir %SUBFILENAME%echo "你好,欢迎来到极客页面" > %SUBFILENAME%.txt
不要忘记像往常一样同时按下CTRL 和 S键来保存文件。
第 4 步:双击您的批处理脚本以执行它。
第5步:你去!现在使用默认文本Hello, Welcome to The Geek Page创建了一个新文件。您可以双击文本文件将其打开。您可以编辑文件并根据您的选择添加任何文本,就像您通常编辑和保存文本文件的方式一样。享受!
第三节:如何根据系统当前时间戳自动创建文件夹和文件并命名
在本节中,双击批处理文件后,将自动创建一个文件和一个文件夹,它们都将根据系统当前的时间戳命名。
第 1 步:右键单击您在第 2 节中创建的批处理脚本,然后单击显示更多选项。
第 2 步:单击下一步中的“编辑”选项。
第 3 步:要创建文件夹以及文件,请从mkdir行的开头删除:: 。
您的最终脚本应如下所示。
回声设置 CUR_YYYY=%date:~10,4%设置 CUR_MM=%date:~4,2%设置 CUR_DD=%date:~7,2%设置 CUR_HH=%time:~0,2%如果 %CUR_HH% lss 10(设置 CUR_HH=0%time:~1,1%)设置 CUR_NN=%time:~3,2%设置 CUR_SS=%time:~6,2%设置 CUR_MS=%time:~9,2%设置 SUBFILENAME=%CUR_DD%%CUR_MM%%CUR_YYYY%_%CUR_HH%%CUR_NN%%CUR_SS%mkdir %SUBFILENAME%echo "你好,欢迎来到极客页面" > %SUBFILENAME%.txt
与往常一样,同时按CTRL + S键保存文件。
第4步:保存后双击批处理文件执行。
第5步:瞧!您可以看到现在创建了一个新文件和一个文件夹,它们都根据您系统的当前时间戳命名。
The above is the detailed content of How to create and name a file/folder based on current timestamp. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



So, you work hard. Of course, the rough-and-tumble worker has 1,000 Chrome windows and tabs open all the time. You absolutely don't have the patience to open every Chrome window and close them one by one. You will think at least 100 times about how to easily close all open Chrome windows and tabs with just one click! Well, why should you worry while we're here? In this article, we explain how to close all open Chrome windows easily through 2 different methods, a non-geek method and a geek method! Hope you like it! Method 1: Through any open Google Chrome window This method is very simple and involves only one step. So you open a lot of Google

Golang time conversion: How to convert timestamp to string In Golang, time operation is one of the very common operations. Sometimes we need to convert the timestamp into a string for easy display or storage. This article will introduce how to use Golang to convert timestamps to strings and provide specific code examples. 1. Conversion of timestamps and strings In Golang, timestamps are usually expressed in the form of integer numbers, which represent the number of seconds from January 1, 1970 to the current time. The string is

If you're looking for a way to automatically create and name files and folders based on system timestamps, you've come to the right place. There is a super simple way to accomplish this task. The created folders or files can then be used for various purposes such as storing file backups, sorting files based on date, etc. In this article, we will explain in some very simple steps how to automatically create files and folders in Windows 11/10 and name them according to the system’s timestamp. The method used is a batch script, which is very simple. Hope you enjoyed reading this article. Section 1: How to automatically create and name a folder based on the current timestamp of the system Step 1: First, navigate to the parent folder where you want to create the folder,

When developing using PHP programs, you often encounter some warning or error messages. Among them, one error message that may appear is: PHPWarning:date()expectsparameter2tobelong,stringgiven. The error message means: the second parameter of the function date() is expected to be a long integer (long), but what is actually passed to it is a string (string). So, we

In Go, you can use regular expressions to match timestamps: compile a regular expression string, such as the one used to match ISO8601 timestamps: ^\d{4}-\d{2}-\d{2}T \d{2}:\d{2}:\d{2}(\.\d+)?(Z|[+-][0-9]{2}:[0-9]{2})$ . Use the regexp.MatchString function to check if a string matches a regular expression.

Java document interpretation: Usage analysis of the currentTimeMillis() method of the System class, specific code examples are required. In Java programming, the System class is a very important class, which encapsulates some properties and operations related to the system. Among them, the currentTimeMillis method is a very commonly used method in the System class. This article will explain the method in detail and provide code examples. 1. Overview of currentTimeMillis method

Change Date Format in Excel Using Number Format The easiest way to remove time from a date in Excel is to change the number format. This does not remove the time from the timestamp - it just prevents it from displaying in your cell. If you use these cells in calculations, the time and date are still included. To change the date format in Excel using number format: Open your Excel spreadsheet. Select the cell containing your timestamp. In the main menu, select the down arrow at the end of the number format box. Choose a date format. After changing the format, the time will stop appearing in your cells. If you click on one of the cells, the time format is still visible in the formula bar. Use cell formatting

Golang Programming Tool: Best Practices for Timestamp Obtaining Introduction: In software development, timestamp is a very common concept. It is a numeric value that identifies the occurrence of a specific event, usually representing the number of milliseconds or nanoseconds since some reference point in time. In Golang, processing timestamps is very simple and efficient. This article will introduce the best practices for obtaining timestamps in Golang and provide specific code examples. Text: Get the current timestamp In Golang, getting the current timestamp is very simple. we can