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

时间:2012-10-05 02:16:30

标签: batch-file rename batch-rename

我想使用日期&重命名.TXT文件Windows批处理或powershell脚本中的自动增量编号。  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
)

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

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

1 个答案:

答案 0 :(得分: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:请给我一些声誉,这样我就可以给予他人他们提供的帮助!

谢谢!

相关问题