首页 \ 问答 \ Windows批处理脚本,一次压缩文件夹中的文件500个文件(Windows batch script to zip files in a folder 500 files at a time)

Windows批处理脚本,一次压缩文件夹中的文件500个文件(Windows batch script to zip files in a folder 500 files at a time)

我的问题:我们每天都会通过FTP传输将我们的通话录音发送给第三方供应商,作为其提供的分析服务的一个zip文件。 这个过程通过.bat文件自动化很长一段时间,直到传输开始失败。

我们的供应商建议将一个大的zip文件分成几个较小的zip文件来解决问题。

因此,我们的目标是编写一个.bat文件,它将一次记录文件500并压缩它们。 显然,脚本还必须压缩随机数量的文件留在最后

我花了5天的时间在网上进行研究,并且发现了一个在堆栈交换中发布的解决方案,看起来正是我所需要的。

但是,我无法让它正常工作,并希望在确定需要修改哪些内容以便正确执行时提供一些帮助。

以下是目前形式的脚本:

@echo off
Setlocal EnableDelayedExpansion

:: Folder containing files
set input=C:\Temp\CallMiner\Downloads
:: Folder for zips
set output=C:\Temp\CallMiner\Uploads
:: Temp filename to hold list of 500 
set listfile=%temp%\listfile
:: Zip counter
set z=1
:: Files per zip
set n=500

cd /d %input%

if exist %listfile% del %listfile%

set i=0

for %f in (*) do (
    echo [!i!] & set /a i+=1
    echo %f >> %listfile%

    if !i!==%n% (
        7z a %output%\!z!.zip @%listfile%
        set i=0
        set /a !z!+=1
        del %listfile%
    )
)

:: Process remaining files, if any
if exist %listfile% (
    7z a %output%\!z!.zip @%listfile%
    del %listfile%
)

以下是发布的原始脚本,以回答具有类似问题的其他用户:

@echo off
Setlocal EnableDelayedExpansion

:: Folder containing files
set input=D:\temp
:: Folder for zips
set output=D:\output
:: Temp filename to hold list of 10 
set listfile=%temp%\listfile
:: Zip counter
set z=1
:: Files per zip
set n=10

cd /d %input%

if exist %listfile% del %listfile%

set i=0

for %%f in (*.*) do (
    set /a i=!i! + 1
    echo %%f >> %listfile%

    if !i!==%n% (
        rar a %output%\!z!.rar @%listfile%
        set i=0
        set /a z=!z! + 1
        del %listfile%
    )
)

:: Process remaining files, if any
if exist %listfile% (
    rar a %output%\!z!.rar @%listfile%
    del %listfile%
)

当我执行原始脚本只修改了文件位置,数量,压缩程序和删除单个%符号,以便我可以手动执行并观察结果时,我反复收到错误“缺少操作员”(大概每个文件一次在文件夹中)。 据我所知,该错误是引用这一行代码:

set /a i=!i! + 1

我对它所做的每一项修改都会导致不同的结果,但都不是正确的。

我无法确定这是问题的真正原因,还是唯一的问题,我真的很感谢来自更有经验的Windows命令行用户的一些帮助。


My problem: Every day we send our call recordings over to a third party vendor as one zip file via FTP transfer for an analysis service they provide. This process was automated via .bat file for a good long while until suddenly the transfer started failing.

Our vendor has suggested breaking the one large zip file into several smaller ones to resolve the problem.

Therefore, the goal is to write a .bat file that will take the recording files 500 at a time and zip them. Obviously the script must also zip whatever random quantity of files is left at the end.

I have spent 5 days researching this online and I found a solution posted on stack exchange which appeared to be exactly what I need.

However, I cannot get it to work and would appreciate some assistance in determining what needs to be modified for it to execute correctly.

Here is the script in it's current form:

@echo off
Setlocal EnableDelayedExpansion

:: Folder containing files
set input=C:\Temp\CallMiner\Downloads
:: Folder for zips
set output=C:\Temp\CallMiner\Uploads
:: Temp filename to hold list of 500 
set listfile=%temp%\listfile
:: Zip counter
set z=1
:: Files per zip
set n=500

cd /d %input%

if exist %listfile% del %listfile%

set i=0

for %f in (*) do (
    echo [!i!] & set /a i+=1
    echo %f >> %listfile%

    if !i!==%n% (
        7z a %output%\!z!.zip @%listfile%
        set i=0
        set /a !z!+=1
        del %listfile%
    )
)

:: Process remaining files, if any
if exist %listfile% (
    7z a %output%\!z!.zip @%listfile%
    del %listfile%
)

Here is the original script posted to answer another user with a similar issue:

@echo off
Setlocal EnableDelayedExpansion

:: Folder containing files
set input=D:\temp
:: Folder for zips
set output=D:\output
:: Temp filename to hold list of 10 
set listfile=%temp%\listfile
:: Zip counter
set z=1
:: Files per zip
set n=10

cd /d %input%

if exist %listfile% del %listfile%

set i=0

for %%f in (*.*) do (
    set /a i=!i! + 1
    echo %%f >> %listfile%

    if !i!==%n% (
        rar a %output%\!z!.rar @%listfile%
        set i=0
        set /a z=!z! + 1
        del %listfile%
    )
)

:: Process remaining files, if any
if exist %listfile% (
    rar a %output%\!z!.rar @%listfile%
    del %listfile%
)

When I executed the original script having only modified file location, quantity, zip program, and removal of a single % symbol so I could execute it manually and watch the results, I received the error "missing operator" repeatedly (presumably once for each file in the folder). As far as I can tell, that error is referencing this line of code:

set /a i=!i! + 1

Every modification I have made to it has resulted in a different result, none of which are correct.

I cannot say for sure that this is the true cause of the problem, or the only problem and I would really appreciate some assistance from more experienced windows command line users.


原文:https://stackoverflow.com/questions/48792813
更新时间:2022-10-21 16:10

最满意答案

没关系,就去吧! 我唯一做的就是检查我的页面是否回发,然后调用我的javascript!


Nevermind, just go it! The only thing I did was check if my page is post back, then call my javascript!

相关问答

更多
  • 您可以简单地将div设置为服务器控件,如下所示:
    如何只是: public Color BackColor { get { return (Color)(ViewState["BackColor"] ?? Color.White); } set { ViewState["BackColor"] = value; } } How about just: public Color BackColor { get { return (Color)(ViewState["BackColor"] ?? Color.White); } ...
  • 1)两者都在加载之前加载 2)基本上,是的 3)首先应用ViewState,然后应用Post Data 引用斯科特米切尔(见下文) 动态添加的控件必须以编程方式添加到每页访问的网页上。 添加这些控件的最佳时间是在页面生命周期的初始化阶段,即在加载视图状态阶段之前发生。 也就是说,我们希望在加载视图状态阶段到达之前完成控制层次结构。 出于这个原因,最好在代码隐藏类中为Page类的Init事件创建一个事件处理程序,并在其中添加动态控件。 4)除非你在盒子外面做某事,否则ViewState从不修改客户端。 “Vi ...
  • @silky是对的,尽可能禁用它。 我们尝试尽可能多地禁用它。 此外,一旦你尽可能少地使用, 可能值得看看在你的页面中放置这样的东西(或者更好的基页类) Protected Overrides ReadOnly Property PageStatePersister() As PageStatePersister Get Return New SessionPageStatePersister(Me) End Get End Property 但这取决于您拥有多少用户以及您 ...
  • 没关系,就去吧! 我唯一做的就是检查我的页面是否回发,然后调用我的javascript! Nevermind, just go it! The only thing I did was check if my page is post back, then call my javascript!
  • 简短的答案是肯定的,GridView中显示的信息与任何控件的当前状态非常相似,都存储在ViewState中。 但是,我认为如果可能的话,将这些数据从WebControls可用的ViewState集合中解放出来并不容易。 相反,ASP.NET在生命周期中运行事件处理程序之前从ViewState中填充值,因此如果在处理程序中询问GridView对象服务器端,应该会看到单元格的当前值。 The short answer is yes, information shown in the GridView, much ...
  • 使用Session [“name”] = textbox1.text ... 如果我没有弄错,你没有直接控制权或者应该直接控制viewstate。 Use Session["name"] = textbox1.text... If I am not mistaken, you don't have direct control or should have direct control over viewstate.
  • 在上面的代码中,您没有使用ViewState存储SearchClicked值,而是使用Session来存储它。 ViewState以隐藏值的形式保存在页面上,并返回到服务器。 这意味着视图状态存储在浏览器中,并且只要用户在页面上就会持续存在。 会话信息存储在服务器上。 用户会话最终会超时,但其他事情会导致会话重置,例如重建应用程序或编辑web.config文件。 要存储到ViewState,请使用以下内容 public bool SearchClicked { get { return ViewState ...
  • System.Web.UI.Control中的Viewstate集合仅允许您访问该控件的viewstate包,而不是子控件。 所以基本上你不能通过ViewState做你想做的事情。 您可以获取控件通过Request.Form参数发布的值。 例如,如果您有一个控件调用textbox1,您可以通过它获取其发布的值 Request.Form["textbox1"] 根据不同的控制方式,您可能需要对从中获得的值进行一些处理。 对于树形视图,您可以使用它获取其展开状态的发布值 Request.Form[Tree ...
  • 我们自己解决了这个问题。 我们采用PhaseListener并组织视图,因此每个对话只有一个视图槽。 这可能,因为我们禁用了缓存,因此每个对话不需要多个视图。 我们的应用程序需要禁用缓存。 We solved it on our own. We take a PhaseListener and organize the views, so each conversation gets only one view-slot. Thats possible, because we disabled cachin ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)