批处理脚本以删除所有用户桌面上的所有图标

批处理脚本以删除所有用户桌面上的所有图标

本文介绍了批处理脚本以删除所有用户桌面上的所有图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前正在寻找一种从所有用户桌面删除所有图标的方法.我进行了实验,直到制作了以下脚本,该脚本允许我从单个用户中删除所有脚本,但是如果没有硬编码,我将无法将其扩展到单个PC上的所有用户.

Currently looking for a way to delete all icons off of all user desktops. I have experimented until I made the following script that allowed me to delete all from a single user but without hard coding I won't be able to extend this to reach all users on a single PC.

@echo off
cd %%#
del C:\Users\%Userprofile%\Desktop\*.* /s /q
for /r %%# in (.) do rmdir %%# /s
cls

我现在正在寻找是否可以在没有硬编码路径的情况下将其扩展到多个用户,因为我当时不知道当时哪个用户正在使用计算机.

I am now looking to see if it is possible to extend this to multiple users without hard coding paths since I don't happen to know which user might be using the computer at the time.

推荐答案

由于您不想对路径进行硬编码,因此我们可以使用 FOR 来搜索 .ico \ Desktop 中的code>文件.下面的脚本将搜索每个用户的桌面,删除所有.ico文件,然后提示用户完成操作.

Since you don't want to hard code path's, we can use the FOR to search for .ico files located in \Desktop for each user. The script bellow will search each users desktop, remove all .ico files, then prompt the user it has finished.

@ECHO OFF
@GOTO :search

:search
FOR /D %%G IN ("C:\Users\*") DO IF EXIST "%%~fG\desktop\*.ico" (
    set correctDir=%%G\desktop
    goto :foundFile
)
goto :finished

:foundFile
cd "%correctDir%"
del /S *.ico
goto :search

:finished
echo All Icons removed from users desktops!
pause
goto :eof

FOR/D 使用 %% G 变量遍历所有目录. %%〜fG 扩展到%% G中目录的完整路径.
IF EXIST 检查文件是否存在.
goto:eof 退出脚本

FOR /D iterates over all directories using the %%G variable. %%~fG expands to the full path to the directory in %%G.
IF EXIST checks if a file exists.
goto :eof exits the script

这篇关于批处理脚本以删除所有用户桌面上的所有图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 23:10