从DOS命令移动除了一些(文件模式)的所有文件 [英] Move all files except some (file pattern) from a DOS command

查看:351
本文介绍了从DOS命令移动除了一些(文件模式)的所有文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在DOS命令我想移动不匹配文件名模式的所有文件。
事情是这样的:

例如我想移动不以AAA

开头的文件

 为%i的(*)做若不%I == AAA *举动%I \\ ..


解决方案

XCOPY 旨在与合作的排除的名单......请看下图:

  DIR / B / A-D来源| FINDSTR / BAAA>中的%temp%\\ aaafiles.tmp   XCOPY源,目的地\\/exclude:%temp%\\aaafiles.tmp / Y

第一行执行的的文件夹,在裸露的格式列表文件( / B )忽略目录的 DIR (目录)上市名字( /广告)。输出管道输送到 FINDSTR 命令。

FINDSTR 着眼于每个文件名,并以字符串进行比较的开始( / B )的 AAA 的。

如果文件名开头的字符串匹配的 AAA 的,文件名被重定向(写入),以文件的 aaafiles.tmp 的在用户的 TEMP 目录。

/ B 是至关重要的,因为你不想要排除的文件,如 theaaafile.txt

XCOPY 命令将文件从的的文件夹复制到的目标的除了文件夹中列出的 aaafiles.tmp

提示覆盖现有文件( / Y )被关闭。

的和的目标的将需要更换自己的foldernames。

From a DOS command I want to move all files that do not match a file name pattern. Something like this:

For example I want to move all files that do not start with "aaa"

for %i in (*) do if not %i == aaa* move %i .\..

解决方案

XCOPY is designed to work with 'exclude' lists... See below:

   dir /b /a-d "source"|findstr /b "aaa" >"%temp%\aaafiles.tmp"

   xcopy "source" "destination\" /exclude:%temp%\aaafiles.tmp /y

The first line performs a DIR (directory) listing of the source folder, listing files in bare format (/b) ignoring directory names (/a-d). The output is piped into the FINDSTR command.

FINDSTR looks at each filename and compares it's beginning (/b) with the string "aaa".

If the start of a filename matches the string "aaa", the filename is redirected (written) to the file aaafiles.tmp in the users TEMP directory.

The /b is vital because you don't want to exclude files such as theaaafile.txt.

The XCOPY command copies files from the source folder to the destination folder except files that are listed in aaafiles.tmp.

Prompting to overwrite existing files (/y) is turned off.

source and destination will need to be replaced your own foldernames.

这篇关于从DOS命令移动除了一些(文件模式)的所有文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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