复制从文件夹1每隔N个文件FOLDER2批处理文件? [英] Batch file for copying every nth file from folder1 to folder2?

查看:179
本文介绍了复制从文件夹1每隔N个文件FOLDER2批处理文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每30文件从一个文件夹复制到另一个和自动化的其他文件夹的过程。我已经尝试在此线程批处理脚本:<一href=\"http://stackoverflow.com/questions/5560371/windows-batch-file-script-to-copy-every-tenth-file-from-a-folder-to-another-fold\">windows批处理文件脚本,每十个文件从一个文件夹并刚刚获得在该命令的语法不正确当我运行该文件(是的,我已经试过两个版本)。 >

我的文件夹确实有名字空间(不是我的选择,不能更改)。该文件被命名为image00000X.jpg是的,有超过他们的100K(这就是为什么我真正想要的脚本工作)。

在理想情况下,我想一个方法来设置脚本了,这​​样我可以只是改变输入和输出路径,并没有运行,当它移到不同的文件夹之间的剧本,但我会满足于尽我所能在这一点上得到,因为我已经尝试只是一切(包括的Robocopy,Xcopy的,五PowerShell脚本,和几个BASH脚本)。

谢谢!


解决方案

您也可以只使用一个标准的循环。我加了一些PARAMS为好,这样可以更改源,目的地,并跳过动态计数:

 参数(
    [字符串] $来源= $(扔必须指定源目录),
    [字符串] $目标= $(抛出您必须指定目标目录),
    [INT] $跳过= 30
)$文件= GET-ChildItem -Path $来源 - 文件为($ IDX = 0; $ IDX -lt $ Files.count; $ IDX + = $跳过){
    $文件[$ IDX] |布展项目-Destination $目的地
}

来源目标是必需的参数,可以但跳过默认为30,如果你不指定一个值。使用时,将其命名为类似 move30th.ps1 ,并运行它,如:

  \\ move30th.ps1  - 源C:\\路径\\为\\文件。-DestinationC:\\新建\\路径-Skip 30

I am trying to copy every 30th file from one folder to another and automate the process for other folders. I have already tried the batch script in this thread: windows batch file script to copy every tenth file from a folder to another folder and just get "The syntax in that command is incorrect" when I run the file (and yes, I've tried both versions).

My folders do have spaces in the names (not my choice and cannot be changed). The files are named image00000X.jpg and yes, there are over 100k of them (which is why I really want the script to work).

Ideally, I'd like a way to set the script up so that I could just change the input and output paths and not have to move the script between the different folders when running it but I'll settle for whatever I can get at this point because I have tried just about everything else (including robocopy, Xcopy, five Powershell scripts, and a few BASH scripts).

Thanks!

解决方案

You can also use just a standard for loop. I added some params as well, so you can change the source, destination, and skip count on the fly:

param(
    [string]$Source = $( throw "You Must Specify Source Directory" ),
    [string]$Destination = $( throw "You Must Specify Destination Directory" ),
    [int]$Skip = 30
)

$Files = Get-ChildItem -Path $Source -File

for( $idx = 0; $idx -lt $Files.count; $idx += $Skip ) {
    $Files[$idx] | Move-Item -Destination $Destination
}

Source and Destination are required params, but Skip defaults to 30 if you don't specify a value. To use, name it something like move30th.ps1, and run it like:

.\move30th.ps1 -Source "C:\Path\To\Files" -Destination "C:\New\Path" -Skip 30

这篇关于复制从文件夹1每隔N个文件FOLDER2批处理文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆