文件的连续编号蝙蝠文件 [英] Continuous numbering of files with bat-file

查看:268
本文介绍了文件的连续编号蝙蝠文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个文件夹,我把我所有的.ild文件。问题是,他们都应该编号,我需要一个批处理脚本来做到这一点。

我把我的文件夹ILDS中的所有ILDS。

现在我得在ILDS文件夹中这3个文件:

  09.ild
test.ild
间用权证d.ild

如何重命名他们,因此他们将其命名为:

  1.ild
2.ild
3.ild

谢谢!


解决方案

 关闭@echo
SETLOCAL disableDelayedExpansion
PUSHDC:\\ somePath \\ ILDS
设置N = 0
为%% f由于(* .ild)做(
  设置文件= %% F
  SETLOCAL enableDelayedExpansion
  集/ A N + = 1
  仁!文件! !N!.ildnew
  ENDLOCAL

仁* .ildnew * .ild
POPD

重命名必须在两个步骤中进行,因为在给定number.ild可能已经存在。

请注意:该脚本可以运行多次,但一旦有10个或更多的文件,该号码将在每次运行时重新分配。换句话说,名为1.ild首次文件不会在第二次运行后的同一文件中。

I have a this folder where I keep all my .ild files. problem is that they should all be numbered, and I need a batch script to do this.

I keep all my ilds in the folder ILDS.

Right now I have these 3 files in the "ILDS" folder:

09.ild
test.ild
s p a c e d.ild

How can i rename them, so they will be named:

1.ild
2.ild
3.ild

Thanks!

解决方案

@echo off
setlocal disableDelayedExpansion
pushd "c:\somePath\ilds"
set "N=0"
for %%F in (*.ild) do (
  set "file=%%F"
  setlocal enableDelayedExpansion
  set /a N+=1
  ren "!file!" "!N!.ildnew"
  endlocal
)
ren *.ildnew *.ild
popd

The rename must be done in two steps because a given number.ild may already exist.

Note: The script can be run multiple times, but once there are 10 or more files, the numbers will be reassigned each time it is run. In other words, the file that is named 1.ild the first time will not be the same file after the second run.

这篇关于文件的连续编号蝙蝠文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆