如果变量批处理可以找到字符串(现有代码需要编辑)

时间:2021-08-11 02:08:31

I have devised a way to remove a files name from its path and extension (replacing the files name with an asterisk).

我已经设计了一种方法来从其路径和扩展名中删除文件名(用星号替换文件名)。

However the out put file adds an extra space just before the closing quotation marks and i dont know why or how to fix this?

然而,输出文件在结束引号之前增加了一个额外的空间,我不知道为什么或如何解决这个问题?

@echo off

SET EXTENT=%~x1
SET PATH=%~dp1

SET /P FILETYPE=

rem SET FILETYPE="%PATH%*%EXTENT%"

echo %FILETYPE%

pause

Type C:\HELLO.txt | findstr /I /V /C:%FILETYPE% >>C:\TEMP.txt

DEL /S/Q "C:\HELLO.txt"

ren "C:\TEMP.txt" "HELLO.txt"

DEL /s/q "C:\TEMP.txt"

1 个解决方案

#1


0  

UPDATED

I changed this answer after gaining a better understanding of the question.

在更好地理解了这个问题后,我改变了这个答案。

I think this code is close to what you want. You may need to play around with regexes for the FINDSTR command.

我认为这段代码接近你想要的。您可能需要使用FINDSTR命令的正则表达式。

@ECHO OFF

SET EXT=%~x1

FINDSTR /I /V /C:%EXT% HELLO.TXT >>TEMP.TXT
DEL /Q HELLO.TXT
REN TEMP.TXT HELLO.TXT

#1


0  

UPDATED

I changed this answer after gaining a better understanding of the question.

在更好地理解了这个问题后,我改变了这个答案。

I think this code is close to what you want. You may need to play around with regexes for the FINDSTR command.

我认为这段代码接近你想要的。您可能需要使用FINDSTR命令的正则表达式。

@ECHO OFF

SET EXT=%~x1

FINDSTR /I /V /C:%EXT% HELLO.TXT >>TEMP.TXT
DEL /Q HELLO.TXT
REN TEMP.TXT HELLO.TXT