How to create and name a file/folder based on current timestamp
Apr 27, 2023 pm 11:07 PMIf 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.
回聲設(shè)置 CUR_YYYY=%date:~10,4%設(shè)置 CUR_MM=%date:~4,2%設(shè)置 CUR_DD=%date:~7,2%設(shè)置 CUR_HH=%time:~0,2%如果 %CUR_HH% lss 10(設(shè)置 CUR_HH=0%time:~1,1%)設(shè)置 CUR_NN=%time:~3,2%設(shè)置 CUR_SS=%time:~6,2%設(shè)置 CUR_MS=%time:~9,2%設(shè)置 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.
設(shè)置CUR_YYYY =%date:~10,4%設(shè)置CUR_MM =%date:~4,2%設(shè)置CUR_DD =%date:~7,2%設(shè)置CUR_HH =%time:~0,2%如果 %CUR_HH% lss 10(設(shè)置 CUR_HH=0%time:~1,1%)設(shè)置CUR_NN =%time:~3,2%設(shè)置CUR_SS =%time:~6,2%設(shè)置CUR_MS =%time:~9,2%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 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.
設(shè)置 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.
設(shè)置 SUBFILENAME=%CUR_YYYY%-%CUR_MM%-%CUR_DD%_%CUR_SS%.%CUR_HH%.%CUR_NN%
Results ==>
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.
?設(shè)置 SUBFILENAME=%CUR_DD%-%CUR_MM%-%CUR_YYYY%_%CUR_HH%-%CUR_NN%-%CUR_SS%
Result==>
- If you want the Date
- element and TimeWithout separators between elements, but requiring a hyphen between date and time, SUBFILENAME would be:
? 設(shè)置 SUBFILENAME=%CUR_DD%%CUR_MM%%CUR_YYYY%_%CUR_HH%%CUR_NN%%CUR_SS%
Result==>
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步:魔術(shù)!將在與批處理腳本相同的文件夾內(nèi)創(chuàng)建一個(gè)新文件夾,其命名基于系統(tǒng)的當(dāng)前時(shí)間戳。
第 2 節(jié):如何根據(jù)系統(tǒng)的當(dāng)前時(shí)間戳自動(dòng)創(chuàng)建文件并命名
在第 1 節(jié)中,我們創(chuàng)建了一個(gè)基于系統(tǒng)當(dāng)前時(shí)間戳命名的文件夾。在本節(jié)中,讓我們看看如何根據(jù)系統(tǒng)當(dāng)前的時(shí)間戳自動(dòng)創(chuàng)建文件并為其命名。
首先,創(chuàng)建第 1 節(jié)中詳述的批處理文件。
第 1 步:右鍵單擊您從第 1 節(jié)創(chuàng)建的批處理文件,然后單擊顯示更多選項(xiàng)。
第 2 步:從展開(kāi)的菜單中,單擊“編輯”選項(xiàng)。
第 3 步:現(xiàn)在,注釋掉最后的mkdir?行。這是負(fù)責(zé)制作文件夾的腳本部分。
要在批處理腳本中注釋掉?一行,您需要在該行的開(kāi)頭添加2 個(gè)冒號(hào)。這將使腳本忽略冒號(hào)后面的行。因此,您的 mkdir 行將如下所示,并且在腳本執(zhí)行期間將被忽略。
::mkdir %SUBFILENAME%
現(xiàn)在,讓我們使用相同的命名格式添加將創(chuàng)建文件的行。
echo "你好,歡迎來(lái)到極客頁(yè)面" > %SUBFILENAME%.txt
因此,需要出現(xiàn)在批處理腳本文件中的最終代碼應(yīng)如下所示。
回聲設(shè)置 CUR_YYYY=%date:~10,4%設(shè)置 CUR_MM=%date:~4,2%設(shè)置 CUR_DD=%date:~7,2%設(shè)置 CUR_HH=%time:~0,2%如果 %CUR_HH% lss 10(設(shè)置 CUR_HH=0%time:~1,1%)設(shè)置 CUR_NN=%time:~3,2%設(shè)置 CUR_SS=%time:~6,2%設(shè)置 CUR_MS=%time:~9,2%設(shè)置 SUBFILENAME=%CUR_DD%%CUR_MM%%CUR_YYYY%_%CUR_HH%%CUR_NN%%CUR_SS%::mkdir %SUBFILENAME%echo "你好,歡迎來(lái)到極客頁(yè)面" > %SUBFILENAME%.txt
不要忘記像往常一樣同時(shí)按下CTRL 和 S鍵來(lái)保存文件。
第 4 步:雙擊您的批處理腳本以執(zhí)行它。
第5步:你去!現(xiàn)在使用默認(rèn)文本Hello, Welcome to The Geek Page創(chuàng)建了一個(gè)新文件。您可以雙擊文本文件將其打開(kāi)。您可以編輯文件并根據(jù)您的選擇添加任何文本,就像您通常編輯和保存文本文件的方式一樣。享受!
第三節(jié):如何根據(jù)系統(tǒng)當(dāng)前時(shí)間戳自動(dòng)創(chuàng)建文件夾和文件并命名
在本節(jié)中,雙擊批處理文件后,將自動(dòng)創(chuàng)建一個(gè)文件和一個(gè)文件夾,它們都將根據(jù)系統(tǒng)當(dāng)前的時(shí)間戳命名。
第 1 步:右鍵單擊您在第 2 節(jié)中創(chuàng)建的批處理腳本,然后單擊顯示更多選項(xiàng)。
第 2 步:?jiǎn)螕粝乱徊街械摹?strong>編輯”選項(xiàng)。
第 3 步:要?jiǎng)?chuàng)建文件夾以及文件,請(qǐng)從mkdir行的開(kāi)頭刪除:: 。
您的最終腳本應(yīng)如下所示。
回聲設(shè)置 CUR_YYYY=%date:~10,4%設(shè)置 CUR_MM=%date:~4,2%設(shè)置 CUR_DD=%date:~7,2%設(shè)置 CUR_HH=%time:~0,2%如果 %CUR_HH% lss 10(設(shè)置 CUR_HH=0%time:~1,1%)設(shè)置 CUR_NN=%time:~3,2%設(shè)置 CUR_SS=%time:~6,2%設(shè)置 CUR_MS=%time:~9,2%設(shè)置 SUBFILENAME=%CUR_DD%%CUR_MM%%CUR_YYYY%_%CUR_HH%%CUR_NN%%CUR_SS%mkdir %SUBFILENAME%echo "你好,歡迎來(lái)到極客頁(yè)面" > %SUBFILENAME%.txt
與往常一樣,同時(shí)按CTRL + S鍵保存文件。
第4步:保存后雙擊批處理文件執(zhí)行。
第5步:瞧!您可以看到現(xiàn)在創(chuàng)建了一個(gè)新文件和一個(gè)文件夾,它們都根據(jù)您系統(tǒng)的當(dāng)前時(shí)間戳命名。
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

Undress AI Tool
Undress images for free

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

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

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

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

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

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

Timestamp handling in PHP: How to format a timestamp into a localized date time using the strftime function When developing PHP applications, we often need to deal with dates and times. PHP provides powerful date and time processing functions, among which the strftime function allows us to format timestamps into localized date and time. The strftime function has the following syntax: strftime(string$format[,int$timestamp=ti

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.

How to get millisecond representation of date using getTime() method of Date class In Java, Date class is a class used to represent date and time. It provides many useful methods to manipulate and obtain information about date objects. Among them, the getTime() method is an important method in the Date class, which can return the millisecond representation of the date object. Next, we will detail how to use this method to obtain the millisecond representation of a date, and provide corresponding code examples. Using the Date class