Table of Contents
Section 1: How to automatically create and name a folder based on the current timestamp of the system
第 2 节:如何根据系统的当前时间戳自动创建文件并命名
第三节:如何根据系统当前时间戳自动创建文件夹和文件并命名
Home Common Problem How to create and name a file/folder based on current timestamp

How to create and name a file/folder based on current timestamp

Apr 27, 2023 pm 11:07 PM
Timestamp Batch processing date

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.

How to create and name a file/folder based on current timestamp

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.

How to create and name a file/folder based on current timestamp

Step 2: Nowdouble-clickthe newly created text document to edit it.

How to create and name a file/folder based on current timestamp

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%
Copy after login

How to create and name a file/folder based on current timestamp

After you finish copying the above script,

Don’t forget to press the CTRL S key at the same time to save the file.

Script description

This script first

extracts 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%
Copy after login

So the variables created are as follows:

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 milliseconds

The 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%
Copy after login

Finally, use the mkdir command to create the folder.

mkdir %SUBFILENAME%
Copy after login

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 login
  • Results ==>
2022-04-15_58.21.15

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 login
  • Result==>
15-04-2022_21-18-26

    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 login
  • Result==>
15042022_211849

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

extension

as bat. This is the most important part.

How to create and name a file/folder based on current timestamp

Step 5

: After renaming and clicking elsewhere, you will see the Rename Confirmation dialog box. Click the Yes button to proceed to the next step.

How to create and name a file/folder based on current timestamp

Step 6

: Your batch script is now ready to execute. Double-click the file to execute it.

第7步:魔术!将在与批处理脚本相同的文件夹内创建一个新文件夹,其命名基于系统的当前时间戳。

How to create and name a file/folder based on current timestamp

第 2 节:如何根据系统的当前时间戳自动创建文件并命名

在第 1 节中,我们创建了一个基于系统当前时间戳命名的文件夹。在本节中,让我们看看如何根据系统当前的时间戳自动创建文件并为其命名。

首先,创建第 1 节中详述的批处理文件

第 1 步右键单击您从第 1 节创建的批处理文件,然后单击显示更多选项

How to create and name a file/folder based on current timestamp

第 2 步:从展开的菜单中,单击“编辑”选项。

How to create and name a file/folder based on current timestamp

第 3 步:现在,注释掉最后的mkdir 。这是负责制作文件夹的脚本部分。

要在批处理脚本注释掉 一行,您需要在该行的开头添加2 个冒号。这将使脚本忽略冒号后面的行。因此,您的 mkdir 行将如下所示,并且在脚本执行期间将被忽略。

::mkdir %SUBFILENAME%
Copy after login

现在,让我们使用相同的命名格式添加将创建文件的行。

echo "你好,欢迎来到极客页面" > %SUBFILENAME%.txt
Copy after login

因此,需要出现在批处理脚本文件中的最终代码应如下所示。

回声设置 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
Copy after login

How to create and name a file/folder based on current timestamp

不要忘记像往常一样同时按下CTRL 和 S键来保存文件。

第 4 步双击您的批处理脚本以执行它。

How to create and name a file/folder based on current timestamp

第5步:你去!现在使用默认文本Hello, Welcome to The Geek Page创建了一个新文件。您可以双击文本文件将其打开。您可以编辑文件并根据您的选择添加任何文本,就像您通常编辑和保存文本文件的方式一样。享受!

How to create and name a file/folder based on current timestamp

第三节:如何根据系统当前时间戳自动创建文件夹和文件并命名

在本节中,双击批处理文件后,将自动创建一个文件和一个文件夹,它们都将根据系统当前的时间戳命名。

第 1 步右键单击您在第 2 节中创建的批处理脚本,然后单击显示更多选项

How to create and name a file/folder based on current timestamp

第 2 步:单击下一步中的“编辑”选项。

How to create and name a file/folder based on current timestamp

第 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
Copy after login

How to create and name a file/folder based on current timestamp

与往常一样,同时按CTRL + S键保存文件。

第4步:保存后双击批处理文件执行。

How to create and name a file/folder based on current timestamp

第5步:瞧!您可以看到现在创建了一个新文件和一个文件夹,它们都根据您系统的当前时间戳命名。

How to create and name a file/folder based on current timestamp

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to close all Google Chrome windows and tabs at once How to close all Google Chrome windows and tabs at once Apr 14, 2023 pm 05:28 PM

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 processing: How to convert timestamp to string in Golang Golang time processing: How to convert timestamp to string in Golang Feb 24, 2024 pm 10:42 PM

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

How to create and name a file/folder based on current timestamp How to create and name a file/folder based on current timestamp Apr 27, 2023 pm 11:07 PM

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,

PHP Warning: date() expects parameter 2 to be long, string given solution PHP Warning: date() expects parameter 2 to be long, string given solution Jun 22, 2023 pm 08:03 PM

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

How to match timestamps using regular expressions in Go? How to match timestamps using regular expressions in Go? Jun 02, 2024 am 09:00 AM

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 documentation interpretation: Usage analysis of the currentTimeMillis() method of the System class Java documentation interpretation: Usage analysis of the currentTimeMillis() method of the System class Nov 03, 2023 am 09:30 AM

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

How to remove time from date in Excel How to remove time from date in Excel May 17, 2023 am 11:22 AM

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

Best Practices for Timestamp Obtaining: A Powerful Tool in Golang Programming Best Practices for Timestamp Obtaining: A Powerful Tool in Golang Programming Dec 29, 2023 am 08:28 AM

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