【发布时间】:2016-06-02 13:50:45
【问题描述】:
我有一个存放大量 .tif 文件的文件夹。
它们都以MW_ 或SW_ 开头,后来还有NSSW。所以我需要能够从后面的前两个扩展到NSSW。
我已经有一个批处理文件,它首先根据文件名的前 2 个字符将文件移动到文件夹 MW 或 SW。这是我当前的批处理文件,它工作得很好。但我认为我需要第二个批处理文件或添加此文件来执行以下 1 和 2 步骤。请看下面,在这段代码之后。
REM Sort by First name.
REM This script creates a folder for either the full file name,
REM or if it contains an underscore, the part before the underscore.
REM TODO - Don't copy over existing files.
REM TODO - Move files into Sub folders based on Date in file name "last 8 characters .tif
@echo off
REM Needed because you are working with variables that are immediately called
setlocal enabledelayedexpansion
REM Start of the loop to get all files with a psd or jpg Extension
for %%A in (*.tif *.jpg *.pdf) do (
echo file found %%A
REM Grabs only the file name
for /f "delims=" %%B in ("%%A") do set fname=%%~nB
REM Grabs only the extension
for /f "delims=" %%C in ("%%A") do set fextn=%%~xC
REM Using the File name it separates it into 2 part using "_" as a delimiter so 120_low becomes 120 and low
for /f "tokens=1* delims=_" %%D in ("!fname!") do set folname=%%D
echo folder name !folname!
REM Checks for the existence of the folder, if the folder does not exist it creates the folder
if not exist "!folname!" (
echo Folder !folname! does not exist, creating
md "!folname!"
) else (
echo Folder !folname! exists
)
REM Moves the file to the folder
echo Moving file %%A to folder !folname!
REM if not exist "%%D\%%A" move "%%A" "!folname!"
if not exist "%%D\%%A" copy "%%A" "!folname!"
REM add the date DDMMYYYY to the end of each file. Name can be 80 characters long.
rem ren "!folname!\%%A" "????????????????????????????????????????????????????????????????????????????????_%date:~-10,2%%date:~-7,2%%date:~-4,4%.tif"
)
echo Finished
pause
所以我猜这就是我需要的。执行以下操作的第二个或第三个批处理文件。我希望,有人可以提供帮助。
注意:请记住,如果文件存在,它会在移动时重命名副本,文件名末尾带有xxxx(1).tif、xxx(2).tif 等。
根据文件名从文件名的第 4 个到第 10 个字符或从第 4 个字符到第二个或下一个“_”,将现在列在
MW文件夹中的文件移动到新的或现有的子文件夹中.根据文件名的最后8个字符将命名文件夹子文件夹中的文件移动到子日期命名文件夹中。
然后我需要根据文件名“日期部分”的最后 7 个字符将文件从 MW 文件夹移动到新的或现有的子文件夹中。
例如,我们以 MW 文件开头
进入文件夹C:\temp\Test_Moving_Files\的文件
MW_VRL5VF10000_6542234_01052016.TIF
MW_Flybuys_677888_01052016.TIF
MW_VRL5VF10000_333443_02052016.TIF
MW_Flybuys_555555_02052016.TIF
MW_goodguys_534535_02052016.TIF
MW_goodguys_222222_02052016.TIF
MW_Flybuys_123443_03052016.TIF
MW_Flybuys_3545555_03052016.TIF
MW_goodguys_444444_03052016.TIF
MW_goodguys_888888_03052016.TIF
子文件夹的输出应按如下子文件夹排序:
MW\VRL5VF10000\01052016\MW_VRL5VF10000_6542234_01052016.TIF
MW\VRL5VF10000\02052016\MW_VRL5VF10000_333443_02052016.TIF
MW\Flybuys\01052016\MW_Flybuys_677888_01052016.TIF
MW\Flybuys\02052016\MW_Flybuys_555555_02052016.TIF
MW\Flybuys\03052016\MW_Flybuys_123443_03052016.TIF
MW\Flybuys\03052016\MW_Flybuys_3545555_03052016.TIF
MW\goodguys\01052016\MW_goodguys_222222_02052016.TIF
MW\goodguys\02052016\MW_goodguys_534535_02052016.TIF
MW\goodguys\03052016\MW_goodguys_444444_03052016.TIF
MW\goodguys\03052016\MW_goodguys_888888_03052016.TIF
【问题讨论】:
标签: batch-file