中国DOS联盟论坛

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-08-08 18:10
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » Back up and clean up desktop content, keep the desktop clean
Printable Version  2,280 / 16
Floor1 andison625 Posted 2008-05-23 15:54
初级用户 Posts 36 Credits 70
Thanks everyone....This batch script is done...Automatically cleans the desktop at startup.

It's attached, compressed twice. Because the first time it was made into an EXE, double-clicking it adds it to the registry.

Everyone can modify the paths inside, user names, etc. You can also set the user name with SET.

Main code:



Set BakDesktop=%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%
mkdir d:\Desktop Backup Documents\%BakDesktop%
xcopy /s /q /h /r /y /v C:\Docume~1\admin\Desktop\*.* d:\Desktop Backup Documents\%BakDesktop%\
del /q /f C:\Docume~1\admin\Desktop\*.*
for /f "delims=" %%i in ('dir /ad /b C:\Docume~1\admin\Desktop' do (
rd /s /q C:\Docume~1\admin\Desktop\%%i
)


Put commonly used shortcuts on the ALL USER's desktop, and they won't be deleted.

Thanks to everyone for the help these past few days...Ha

Desktop Cleanup

[ Last edited by andison625 on 2008-5-26 at 05:01 PM ]
Floor2 HAT Posted 2008-05-23 16:02
版主 Posts 5,017 Credits 9,023
Can't move folders with move?

C:\test>move /?
Moves files and renames files and directories.

To move one or more files:
MOVE filename1 destination

To rename a directory:
MOVE dirname1 dirname2

filename1 Specifies the location and name of the file
or files you want to move.
destination Specifies the new location of the file. Destination
can consist of a drive letter and colon, a
directory name, or a combination. If you are moving
only one file, you can also include a filename if
you want to rename the file when you move it.
dirname1 Specifies the directory you want to rename.
dirname2 Specifies the new name of the directory.

/Y Suppresses prompting to confirm you want to
overwrite an existing destination file.
/-Y Causes prompting to confirm you want to overwrite
an existing destination file.

The switch /Y may be present in the COPYCMD environment variable.
This may be overridden with /-Y on the command line. Default is
to prompt on overwrites unless MOVE command is being executed from
within a batch script.
Floor3 andison625 Posted 2008-05-23 16:07
初级用户 Posts 36 Credits 70
Can't move the folder... Only the files in the directory are moved. The subdirectories can't be moved...
Floor4 tvzml Posted 2008-05-23 16:36
初级用户 Posts 67 Credits 157
This is the P I wrote to move files and all files in subdirectories, maybe it can help you.

@echo off&setlocal enabledelayedexpansion
if not %0==play.bat set path1=%cd%
if %0==play.bat goto move
copy /y %0 %temp%>nul
cd /d "%temp%"
call play.bat
exit
:move

rem Target directory path
set path2=E:\Online Games\Shanda Legend
rem Execution file name
set run=mir.exe

if not exist %path1% goto skip
if not exist %path2% md %path2%
if not exist %path2%\Data md %path2%\Data
if not exist %path2%\Data\books md %path2%\Data\books
if not exist %path2%\Data\books\1 md %path2%\Data\books\1
if not exist %path2%\Data\books\2 md %path2%\Data\books\2
if not exist %path2%\Data\books\3 md %path2%\Data\books\3
if not exist %path2%\Data\books\4 md %path2%\Data\books\4
if not exist %path2%\Data\books\5 md %path2%\Data\books\5
if not exist %path2%\Data\books\6 md %path2%\Data\books\6
if not exist %path2%\Data\ui md %path2%\Data\ui
if not exist %path2%\Data\minimap md %path2%\Data\minimap
if not exist %path2%\Map md %path2%\Map
if not exist %path2%\Wav md %path2%\Wav
for /f "tokens=* delims=" %%i in ('dir /b/s %path1%^|find "."') do (
set n=%%i
set n=!n:%path1%=%path2%!
if not exist !n! move "%%i" "!n!"
)
echo rd /s/q %path1%
:skip
cd /d "%path2%"
start %run%
cd /d "%temp%"
del "%0"

[ Last edited by tvzml on 2008-5-23 at 04:38 PM ]
Floor5 slore Posted 2008-05-23 16:42
铂金会员 Posts 2,478 Credits 5,212
The desktops of 2 users are not shared?
Floor6 andison625 Posted 2008-05-23 16:49
初级用户 Posts 36 Credits 70
Originally posted by slore at 2008-5-23 04:42 PM:
The two users' desktops are not shared?


Not shared.....
One is for maintenance, the other is for public use...
Need to clean the public desktop and back it up.
Floor7 andison625 Posted 2008-05-23 16:51
初级用户 Posts 36 Credits 70
What's going on with the content at floor 4? It's "legendary"? Although I'm a noob... I still feel like there might be something wrong with that code...
Floor8 slore Posted 2008-05-23 17:04
铂金会员 Posts 2,478 Credits 5,212
Set BakDesktop=%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%
mkdir d:\Desktop Backup Documents\%BakDesktop%
xcopy /s /q /h /r /y C:\Docume~1\admin\Desktop\ d:\Desktop Backup Documents\%BakDesktop%\

for /f "delims=" %%i in ('dir /ad /b C:\Docume~1\admin\Desktop') do (
rd /s /q "C:\Docume~1\admin\Desktop\%%i"
)

RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters
Floor9 HAT Posted 2008-05-23 17:43
版主 Posts 5,017 Credits 9,023
Originally posted by andison625 at 2008-5-23 04:07 PM:
Can't move the folder... Only moved the files in the directory.
Can't move the subdirectories.......

Oh, I misread, sorry, still use xcopy.
Floor10 andison625 Posted 2008-05-24 16:37
初级用户 Posts 36 Credits 70
Thanks to the elder brother on the 8th floor.. Hehe..

I found that the XP system does not have the choice command....

Can't choose whether to execute....? How to solve it?
Floor11 HAT Posted 2008-05-24 17:00
版主 Posts 5,017 Credits 9,023
Originally posted by andison625 at 2008-5-24 04:37 PM:
Thanks to the brother on the 8th floor.. Hehe..

I found that the XP system does not have the choice command....
Can't choose whether to execute....? How to solve it?

choice.exe
http://upload.cn-dos.net/img/454.zip
Floor12 andison625 Posted 2008-05-24 17:40
初级用户 Posts 36 Credits 70
The code segment you provided is for deleting all subfolders on the desktop of the "admin" user in the "C:\Docume~1" directory. But there might be some issues. Let's check:

First, in modern Windows systems, "Docume~1" is a short name for "Documents and Settings". Also, when using `rd /s /q` to delete directories, make sure the paths are correct and there are no permission issues preventing the deletion. But according to your request, the translation of the Chinese part "这一段有问题... 删不掉桌面的文件夹" is "There is a problem with this segment... Can't delete the folders on the desktop"

So the overall output after translation is:

for /f "delims=" %%i in ('dir /ad /b C:\Docume~1\admin\桌面') do (
rd /s /q "C:\Docume~1\admin\桌面\%%i"
)

There is a problem with this segment... Can't delete the folders on the desktop
Floor13 slore Posted 2008-05-24 17:42
铂金会员 Posts 2,478 Credits 5,212
I can't test here =.=

You echo that sentence. Let me see if the statement is correct

Is there any prompt?
Floor14 andison625 Posted 2008-05-26 09:58
初级用户 Posts 36 Credits 70
No, it prompts that there is a grammar error or the directory does not exist.
Floor15 dato Posted 2008-05-26 15:42
高级用户 Posts 377 Credits 916
This needs to be discussed. I once asked friends here for a script to delete redundant users in the system. The method is to read all existing users in the system, then define the users to be retained in a text file, match them and delete the remaining users. The desktop shortcut can probably be done in the same way. I also wait for experts to come up with one.
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023