Get the App
SLTechnology News&Howtos  ›  Development  › 

How to rename according to the contents of a file in batch processing

Shulou Source: shulou.com Published: 2022-06-03 08:17:09 11月15日 Update

This article will explain in detail how batch processing can be renamed according to the contents of the file. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

I want to achieve the following goals:

First of all, I have a .dat file whose name is fixed and needs to be changed.

The content of the first line of .dat is: 10107xxxxxx, which means 2007.01.01, and the following x content is not fixed. If it is from January to September, the first character is empty.

Now we need to change the file name according to the contents of this line. For example, 10107XXXXXX, change to c01-0101.cvs.

110107xxxxxx, changed to c01-1101.cvs

Please tell me how to write this BAT file.

Analysis:

Read the first line to a variable

The fifth character of the area variable, you can judge whether it is 0 or not

1) if it is 0, take the first two digits of the variable as the month, otherwise take the first one and prefix 0 as the month

2) if it is 0, take 3-4 digits as the month, otherwise take 2-3 digits as the day

Answer:

@ echo off for% I in (* .dat) do call: goren% i goto end: goren set / p firstln=

Tags: Content file variable month article character file name more good practical line representative prefix name meaning article purpose knowledge analysis reference Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS Huawei Shulou Technology vpn