从远程文件夹批量增加文件名

问题描述 投票:0回答:1

我想在Windows批处理或powershell脚本中使用日期和自动增量编号重命名.TXT文件。 I.E. 20121004ABC.txt,20121004ABC_02.txt,20121004ABC_03.txt。 。 。

棘手的部分是这些文件在上传时被移动到另一个文件夹。如果文件位于具有相同日期的存档文件夹中,我希望递增的数字继续...

SO 20121004ABC.txt,20121004ABC_02.txt,20121004ABC_03.txt上传并移动到C:\ return \ archive那天晚些时候4个新的.txt文件放在c:\ return中,我想运行一个批处理文件来命名它们20121004ABC_04.txt,20121004ABC_05.txt,20121004ABC_06.txt,20121004ABC_07.txt

第二天递增的数字将重新开始,20121005ABC.txt,20121004ABC_02.txt到目前为止,我有:

setlocal enabledelayedexpansion
SET date=%date:~-4,4%%date:~-10,2%%date:~-7,2%
set /a count=0
for /f "tokens=*" %%a in ('dir /b /od *.txt') do (
ren %%a %date%_0!count!.txt
set /a count+=1
)

但这显然只是一个开始,并没有回答我的很多问题!

- 不会继续从存档文件夹中递增数字 - 我相信有一些未知的循环函数问题和写入其他文件等!

batch-file rename batch-rename
1个回答
0
投票

正如我所提到的,我是编码和学习的新手。我想出了一种技术来解决我的问题,这可能是凌乱的,但似乎可以做到这一点!我想分享其他人有类似的问题。此外,如果有人对此代码有任何批评,请尽我所能,我将把它作为建设性的批评,并乐意改进我的代码。

也正如另一点可能有用或可能没有用,我使用SQL查询导出txt文件然后使用Cygwin

谢谢!

c:\cygwin\bin\bash C:\s3\return\split.sh 'Shell Script to Split DB Export file into 25000 line Pieces
CD C:\s3\return\Returned_ARCHIVED 'Directory of Archive of Files To continue Counting from
for /f "tokens=*" %%a in ('dir /b /od') do set newest=%%a 'Newest File in Archive Directory
Set Name=%newest:~0,8% 'Take only the important part of the File name
Set /a FileNum=%newest:~12,2% 'Take only the incremental number part off the filename
SET date=%date:~-4,4%%date:~-10,2%%date:~-7,2%
If %date% == %Name% (set /a count=%filenum%+1) Else (set /a count=0) 

'if the latest file in the archive is from today date +1 ifnot Start at 0

cd C:\s3\return 'Directory if Files that need renamed
for /f "tokens=*" %%a in ('dir /b /od ABC_*') do (
ren %%a %date%ABC_0!count!.txt
set /a count+=1
)

PS:请给我一些声誉,所以我可以给予他人他们提供给我的帮助!

谢谢!

© www.soinside.com 2019 - 2024. All rights reserved.