Batch file 远程文件夹中的批增量文件名

Batch file 远程文件夹中的批增量文件名,batch-file,rename,batch-rename,Batch File,Rename,Batch Rename,我想在windows批处理或powershell脚本中使用日期和自动递增编号重命名.TXT文件。 即20121004ABC.txt、20121004ABC_02.txt、20121004ABC_03.txt 棘手的是这些文件在上传时会被移动到另一个文件夹。如果存档文件夹中的文件的日期相同,我希望递增的数字继续 因此,20121004ABC.txt、20121004ABC_02.txt、20121004ABC_03.txt被上载并移动到C:\return\archive 那天晚些时候,4个新的.t

我想在windows批处理或powershell脚本中使用日期和自动递增编号重命名.TXT文件。 即20121004ABC.txt、20121004ABC_02.txt、20121004ABC_03.txt

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

因此,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
)
但这显然只是一个开始,并没有回答我的很多问题

-将不会继续从存档文件夹中递增编号
-我相信在循环函数和写其他文件等方面存在一些未知问题

正如我提到的,我对编码和学习都是新手。我想出了一个技术来解决我的问题,这可能是混乱的,但似乎做的把戏!我想和大家分享一下,以防其他人也有类似的问题。另外,如果有人对这段代码有任何批评,请批评,我会把它作为建设性的批评,并很乐意在我这方面支持这段代码

还有一点可能有用也可能没用,我使用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:请给我一些声誉,这样我就可以给别人的帮助,他们提供我的信用


谢谢

名字的
ABC
部分来自哪里?
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
)