2013-05-15 50 views
1

因此,这一直让我感到恼火。我正在尝试编写一个批处理文件,以便根据文件大小转到他们自己的文件夹中。我已经开始手动执行此操作,但是在三十分钟后,我试着学习如何制作一个.bat文件以减少几个小时的工作。不过,我在Google.com上找不到任何帮助。通常我会查看代码并稍微编辑它以便正常工作,但批处理对我来说仍然非常困惑,而且我还没有发现任何与我正在查找的内容类似的内容。根据文件大小移动文件的批处理文件

到目前为止,我已经搬到859个32KB文件放入一个文件夹中标题为“32” 我已经做了与64KB文件的所有431一样,都是91的96KB的文件,30页128KB的文件,14页160KB的文件,17 192kb的文件,9 224kb的文件,然后是258kb-1376kb都有大约4-5的每一个,然后再按指数规律增长到912mb,我停在640kb。

所以有一种模式,我只需要一个.bat代码将这些文件移动到文件大小后命名的文件夹中。我想象中的另一种编码语言,一个循环做什么,我想会是这个样子,

dim strFS as String 
strFS = "file".filesize 
move "file" to /"strFS" 

回答

0

这样的文件此举可能与下列注释批次进行:

@echo off 
setlocal EnableDelayedExpansion 
for %%F in (*) do (

    rem Divide file size by 32768 
    set /A "BlockSize=%%~zF/32768" 
    rem Calculate remainder of above division. 
    set /A "Remainder=!BlockSize!*32678-%%~zF" 
    rem Multiply result with 32 and round up to 32, 64, 96, 128, ... 
    if "!Remainder!"=="0" (set "Add=0") else (set "Add=32") 
    set /A "FolderName=BlockSize*32+Add" 

    rem Move the file to appropriate directory which fails if the 
    rem directory does not already exist. In this case create the 
    rem directory and execute move command once again. 
    move "%%~nxF" !FolderName!\ 2>nul 
    if errorlevel 1 (
     md !FolderName! 
     if not errorlevel 1 (
      move "%%~nxF" !FolderName! 
     ) else (
      echo Could not create directory !FolderName! for file %%~nxF 
     ) 
    ) 
) 
endlocal 

批处理文件不能在当前的工作目录中,因为它会自动移动,这当然不是一个好主意。

帮助的命令如果的md移动设置SETLOCAL可以通过打开一个命令提示,并用参数/?所附或作为参数输入这些命令被读命令帮助,例如for /?help for

相关问题