Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

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

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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=

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report