Get the App
SLTechnology News&Howtos  ›  Development  › 

How to rename a batch based on the contents of the file

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

I would like to share with you how batch processing is renamed according to the contents of the file. I believe most people don't know much about it, so share this article for your reference. I hope you will gain a lot after reading this article. let's learn about it!

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 offfor% I in (* .dat) do call: goren% igoto end:gorenset / p firstln=

Tags: Content file variable month article character file name line not much representative prefix name most meaning more knowledge industry information channel channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB MySQL Shulou Information Microsoft