批次:找到文件,并将其重命名/查找文件并将其删除 [英] Batch: find file and rename it / find file and delete it

查看:273
本文介绍了批次:找到文件,并将其重命名/查找文件并将其删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以......的确,我pretty新手。仍然试图解释尽可能好。
但是,需要有这样的东西帮助,找到从C确切文件:驱动器(批处理)
并重新命名。
也想知道如何找到C文件:并将其删除。 (2问题1线程...)

So... yes, Im pretty newbie. Still trying to explain as good as possible. But needing help with such thing as finding exact file from C: drive (with batch), and rename it. Also wanted to know how to find file from C: and delete it. (2 problems in 1 thread...)

问题1.例如:我想找到的文件名为从Ctext1.txt:批处理驾驶,
如果成功找到,将其重命名为text2.txt。

Problem 1. example: I want to find file called "text1.txt" from C: drive with batch, if successfully found, rename it as "text2.txt".

问题2.例子:我想找到的文件名为从Cimage1.jpg:批处理驾驶,
如果成功找到,将其删除。

Problem 2. example: I want to find file called "image1.jpg" from C: drive with batch, if successfully found, delete it.

或如何这可能是与一批做什么?德尔此搜索只检查它已经是,与相同重命名文件夹中。如何找到一批从整个C时这些文件:盘?
刚才的例子。 2小事来解决,重命名和通过搜索与批量确切的文件中删除。如何从子文件夹中删除文件,批?
但是,对不起我的小诀窍,必须从某个地方开始这些事情。

Or how this could be done with batch? del image1 only checks same folder where it already is, same with rename. How to find these files with batch from whole C: disk? Just example. 2 little things to solve, rename and delete by searching for exact files with batch. How about deleting file from subfolder with batch? But sorry my low know-how, must start these things from somewhere.

推荐答案

哦,这是伟大的,有一些很好的-寻找热塑成型的程序员!我知道大多数程序员的 UGLY

Oh, it's great to have some good-loking programmers! Most programmers I know are UGLY.

for /f "delims=" %%i in ('dir /s /b /a-d "text.txt"') do (ren "%%i" text2.txt)

应该做重命名任务。你应该尽管prePEND驱动器和启动目录下的文件名,否则将重新命名所有子目录中的所有的text.txt 文件。因此, ... DIR / S / BC:\\用户\\卡斯特\\的text.txt... 将处理C:\\用户\\卡斯特\\和所有下面的目录,并重新命名所有命名文件的的text.txt 来的新名称。

Should do the rename task. You should prepend the drive and starting directory to the filename though, or it will rename ALL the text.txt files in ALL subdirectories. Hence ...dir /s/b "c:\users\kaster\text.txt"... will process "c:\users\kaster\" and all of the directories below and rename ALL of the files named text.txt to the new name.

它通过执行 DIR 扫描在 / B 基本模式(即文件名只) / S 包括子目录 /广告忽视了一个名为的text.txt文件匹配的目录名称 - 和完整的文件名被分配到 %%我。在 delims 子句可以确保任何空格都没有PTED作为分隔符间$ P $。

It works by performing a DIRscan in /b basic mode (ie filenames only) /s including subdirectories /a-d ignoring matching directory names for files named "text.txt" - and the full filename is assigned to %%i. The delims clause makes sure that any spaces are not interpreted as delimiters.

请参阅

`FOR ?` 

从提示的文档。

如果你是直接从命令提示符下执行此,改变每个 %%

ANd if you are executing this directly from the prompt, change each %% to %

第二个命令基本上是easire

The second command is substantially easire

del /s "image1.jpg"

再次prePEND起始路径,为非常,非常小心。这将删除全部中的文件名和指定目录下匹配image1.jpg。

Again, prepend the starting path, and be VERY, VERY careful. This will delete ALL filenames matching "image1.jpg" in and under the specified directory.

在整个援引的文件名可以确保空格中的文件或数据夹的正确处理。

Throughout, quoting the filenames ensures that spaces in file or directorynames are correctly processed.

这篇关于批次:找到文件,并将其重命名/查找文件并将其删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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