开发者

Wildcard in cmd files

开发者 https://www.devze.com 2023-02-23 14:03 出处:网络
I am faced with a situation where I need to delete one file in all users directories E.g. C:\\Users\\User1\\Desktop\\deleteme.tx开发者_如何学JAVAt

I am faced with a situation where I need to delete one file in all users directories

E.g.

C:\Users\User1\Desktop\deleteme.tx开发者_如何学JAVAt
C:\Users\User2\Desktop\deleteme.txt
C:\Users\User3\Desktop\deleteme.txt

I am in need of a command that will treat the users directory as a wildcard, so I don't need to specify anything.

I have tried:

C:\Users\*\Desktop\deleteme.txt

Which doesn't work :(

Any help would be appreciated


You may try iterating the needed folders :

for %%X in (C:\Users\User1 C:\Users\User2 C:\Users\User3) do (del %%X\Desktop\deleteme.txt )

or

for /d %%X in (C:\Users\*) do (del %%X\Desktop\deleteme.txt )

There is a good article Iterating with "For"

UPDATE In this way :

for /d %%A in (C:\Users\*) do for /d %%B in (%%A\*) do echo %%B

You can list all subdirectories in all user's folders.


C:\Users*\Desktop\deleteme.txt

I thought there might be a backslash missing after C:\Users, but it isn't. It's a problem of the syntax here, as I just noticed. A backslash in front of an astrisk is omitted.

If a batch file proves unsufficient and you are working on Windows 7 only, you could switch to PowerShell

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号