![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-09-28 12:15 |
47,813 topics / 349,918 posts / today 0 new / 48,277 members |
| DOS批处理 & 脚本技术(批处理室) » [Help] Remove files in the directory except those with .td and .cfg extensions |
| Printable Version 2,184 / 8 |
| Floor1 bsmqu | Posted 2008-05-28 11:33 |
| 初级用户 Posts 6 Credits 114 | |
|
[Help] Remove files in the directory except those with .td and .cfg extensions
I know I need to first find the filenames other than these two extensions, but I don't know how to do it. Please give me some advice, thank you |
|
| Floor2 bat-zw | Posted 2008-05-28 12:36 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
Assume moving from d:\test to d:\temp
[ Last edited by zw19750516 on 2008-5-28 at 01:08 PM ] |
|
| Floor3 bsmqu | Posted 2008-05-28 16:04 |
| 初级用户 Posts 6 Credits 114 | |
|
I just want to say thank you.
But this processing will also move the files in the subdirectories. It is suggested that when using dir /s /a-d /b, it should be changed to dir /a-d /s |
|
| Floor4 bat-zw | Posted 2008-05-28 16:17 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
Originally posted by bsmqu at 2008-5-28 16:04: I thought the owner wanted to move all, so I added /s. If you don't want to move the files in the subdirectories, you can remove /s. [ Last edited by zw19750516 on 2008-5-28 at 04:23 PM ] |
|
| Floor5 easonL | Posted 2008-05-28 16:46 |
| 初级用户 Posts 56 Credits 118 From 南京 | |
Originally posted by zw19750516 at 2008-5-28 04:17 PM: Why does this error occur when I run it? The error message is: D:\batch>moveFile The system cannot find the file specified. The system cannot find the file specified. Press any key to continue . . . In addition, 'dir /a-d /s' also errors: D:\batch>moveFile The system cannot find the file specified. The system cannot find the file specified. The filename, directory name, or volume label syntax is incorrect. The system cannot find the path specified. The system cannot find the path specified. The system cannot find the file specified. The filename, directory name, or volume label syntax is incorrect. The system cannot find the path specified. The system cannot find the path specified. The system cannot find the file specified. The filename, directory name, or volume label syntax is incorrect. The system cannot find the path specified. The system cannot find the path specified. The system cannot find the path specified. The system cannot find the path specified. The system cannot find the path specified. The system cannot find the file specified. " Total Files Listed:" is not a recognized device. " Total Files Listed:" is not a recognized device. The filename, directory name, or volume label syntax is incorrect. The system cannot find the file specified. The system cannot find the file specified. Press any key to continue . . . Please analyze it, thank you |
|
| Floor6 bat-zw | Posted 2008-05-28 17:24 |
| 金牌会员 Posts 1,276 Credits 3,105 | |
|
Is the path D:\batch\test\temp\ actually existing?
|
|
| Floor7 easonL | Posted 2008-05-28 17:31 |
| 初级用户 Posts 56 Credits 118 From 南京 | |
Originally posted by zw19750516 at 2008-5-28 05:24 PM: It exists. I ran @echo off&setlocal enabledelayedexpansion set str=.td .cfg for /f "delims=" %%i in ('dir/b/a-d "D:\batch\test\*.*"') do ( set "flag=" for %%a in (%str%) do if "%%a"=="%%~xi" set flag=A if not defined flag move /y "%%i" D:\batch\test\temp\ ) pause It works! Very strange, it doesn't work without /s ------------------------------------------------------------- In addition, I tested for /f "delims=" %%i in ('dir/b/a-d "D:\batch\test\*.*"') do ( echo %%~nxi ) It can traverse the files under test, very strange哦 |
|
| Floor8 easonL | Posted 2008-05-28 17:32 |
| 初级用户 Posts 56 Credits 118 From 南京 | |
|
Mistaken, it should be running
for /f "delims=" %%i in ('dir/b/a-d/s "D:\batch\test\*.*"') do ( set "flag=" for %%a in (%str%) do if "%%a"=="%%~xi" set flag=A if not defined flag move /y "%%i" D:\batch\test\temp\ ) pause is okay |
|
| Floor9 easonL | Posted 2008-05-28 17:36 |
| 初级用户 Posts 56 Credits 118 From 南京 | |
|
It should be that this 'dir/b/a-d "D:\batch\test\*.*"' command is okay! Now the situation is that there are several files under the test folder, but it just shows a few lines of "The system cannot find the file specified." error messages. It's very strange. What's the reason? Why does it say the path is incorrect?
|
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |