简体   繁体   English

批处理-使用forfiles删除特定文件

[英]Batch - Delete a specific file with forfiles

I want to do echo only checking the date from one file with forfiles : 我只想用forfiles echo一个文件中的日期:

forfiles /m "C:\Backups\TEST.bak" /c "cmd /c echo test" /d -1

But it returns me an error : 但是它返回了一个错误

The System cannot find the file specified. 该系统找不到指定的文件。

And that file it exists and the directory is correct. 并且该文件存在并且目录正确。

If use forfiles in the same directory (without file) it works fine: 如果在同一目录中使用forfiles (不带文件),则可以正常工作:

forfiles /p "C:\Backups" /c "cmd /c echo test" /d -1

What am I doing wrong? 我究竟做错了什么?

The problem is that forfiles requires a directory as parameter. 问题在于forfiles需要目录作为参数。 You are giving it a file instead. 您正在给它一个文件 This won't work. 这行不通。

Instead you should do this: 相反,您应该这样做:

FOR %%a in (C:\Backups\TEST.bak) DO SET FileDate=%~ta

This will store the file's modifed date in %FileDate% . 这会将文件的修改日期存储在%FileDate%

forfiles /p "c:\Backups" /m "test.bak" /d -1 /c "cmd /c echo @fdate @ftime"

/p needs a folder to start searching /p需要一个文件夹才能开始搜索

/m needs a file mask to indicate what to search /m需要文件掩码以指示要搜索的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 删除特定文件并使用forfiles将文件复制到文件夹 - Delete specific file and copy file to folder using forfiles 批处理-Forfiles循环使用多种文件类型 - Batch - Forfiles in loop with multiple file types ForFiles 使用时间戳批量移动和重命名文件 - ForFiles to batch move & rename file(s) with timestamp FORFILES:仅在RELPATH包含子字符串时删除文件 - FORFILES: Only delete file if RELPATH contains substring 使用FOR或FORFILES批处理命令分别归档特定文件 - Using FOR or FORFILES batch command to individually archive specific files 批处理文件,如果包含特定文件,则删除文件夹 - Batch file to delete folder if it contains specific file 在批处理命令中无法使用forfiles获得文件名的前4个字符 - Not able to get first 4 characters of the file name using forfiles in batch command 批处理文件以在所有驱动器中搜索特定文件并删除该文件 - batch file to search all drives for a specific file and delete that file 使用forfile或潜在的Powershell批量重命名 - Batch renaming with forfiles, or potentially Powershell Windows 批处理文件:FORFILES“日期之间”解决方法 - 如何使 >CON output 可用于 FOR 循环 - Windows Batch file: FORFILES “date between” workaround - how to make >CON output available to FOR loop
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM