2012-10-05 36 views
0

我是社區和編程功能的新手。雖然我喜歡學習。遞增歸檔文件夾的文件名

我想重命名一個.TXT文件,日期&在Windows批處理或PowerShell腳本中自動遞增數字。 I.E. 20121004ABC.txt,20121004ABC_02.txt,20121004ABC_03.txt。 。 。

訣竅部分是這些文件在上傳時被移到不同的文件夾。我希望增加的數字繼續,如果文件是在同一日期的存檔文件夾...

SO 20121004ABC.txt,20121004ABC_02.txt,20121004ABC_03.txt上傳並移動到C:\回報\存檔 後來當天4個新的.txt文件放在C:\回報,我想運行一個批處理文件來命名他們 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 
) 

但這顯然只是一個開始,並不能回答我的很多問題!

- 將不會繼續遞增歸檔文件夾中的數字 - 我相信有一些未知問題的循環功能和寫在其他文件等!

正如我所說我是一名學生學習,所以任何幫助表示讚賞,我很高興能儘可能地學習。

謝謝。

+0

名稱的ABC部分來自哪裏? –

回答

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:請給我一些聲望,這樣我可以給他人信貸,他們爲我提供的幫助!

謝謝!