中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 求助:长文件名显示不正常(高手级的)
作者:
标题: 求助:长文件名显示不正常(高手级的) 上一主题 | 下一主题
jiulong
中级用户




积分 396
发帖 183
注册 2007-12-23
状态 离线
『楼 主』:  求助:长文件名显示不正常(高手级的)

@echo off
set ietmp=%userprofile%\Local Settings\Temporary Internet Files
for /f "tokens=1" %%i in ('dir /ad /s "%ietmp%\*"') do echo %%i
pause

上面是错误的,不能正常显示


用下面的就正确了
for /f "tokens=*" %%i in ('dir /ad /b /s "%userprofile%\Local Settings\Temporary Internet Files\*"') do rd /s/q "%%i"
del /f /s /q "%userprofile%\Local Settings\Temp\*.*"

这条命令有缺陷:如果别人的IE临时目录不在这里呢?而且你又不知道呢?


要实现的目的是:
1、不知道IE临时文件夹所在位置(因为要做个通用的清理垃圾工具),所以不能用SET来变量
2、不能用rd /s/q "path:\Temporary Internet Files"&md "path:\Temporary Internet Files"命令,因这条命令会造成至命错误。我是试过的,不知别人有没有
我这种至命问题

补充:如果用以下命令来设置变量也可以:
@reg add "HKCU\Environment" /v ietmp /t reg_expand_sz /d "%USERPROFILE%\Local Settings\Temporary Internet Files" /f
@reg add "HKLM\SYSTEM\ControlSet001\Control\Session Manager\Environment" /v ietmp /t reg_expand_sz /d "%USERPROFILE%\Local Settings\Temporary Internet Files" /f

然后我可以用这样的命令做:rd /s/q %ietmp%&md %ietmp%

注意:在不知道别人做系统习惯的情况下,又不知他的IE临时目录所在位置
并且他转过又不想换其它位置的情况下要做到通用就有点难了。

[ Last edited by jiulong on 2008-3-5 at 02:47 PM ]

2008-3-5 14:38
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
vkill
金牌会员





积分 4103
发帖 1744
注册 2006-1-20
来自 甘肃.临泽
状态 离线
『第 2 楼』:  

不管转移到那,读取reg都可以找到的

2008-3-5 14:48
查看资料  发送邮件  访问主页  发短消息 网志   编辑帖子  回复  引用回复
fastslz
铂金会员

DOS一根葱


积分 5493
发帖 2315
注册 2006-5-1
来自 上海
状态 离线
『第 3 楼』:  

第1个 "tokens=1"能正常显示才叫怪了
看下面的通用吗
@echo off
regkey=HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
for /f "skip=4 tokens=2,*" %%i in ('reg query "%regkey%" /v "Cache"') do del /f/s/q "%%j\*.*" >nul 2>nul
pause




第一高手    第二高手

2008-3-5 18:43
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
chishingchan
银牌会员




积分 1282
发帖 538
注册 2002-11-2
状态 离线
『第 4 楼』:  结合自己及几位高手帮助后所做成的成品(仅供参考)


@echo off
title 命令提示符
if "%1"=="/?" goto help
if "%1"=="/h" goto help
if "%1"=="/H" goto help
if "%1"=="/u" goto original
if "%1"=="/U" goto original
:: for /f "tokens=2*" %%a in ('reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion" /v ProductName 2^>nul^|findstr "Microsoft"') do @set V=%%b
:: if "%V%"=="" echo This program cannot be run in DOS mode.
:: goto end
title 复制并转移系统资料文件夹向导
:input
cls
echo 当前系统资料文件夹名称及位置。
echo.
for /f "tokens=2*" %%a in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Personal ^|findstr "Personal"') do @set MD=%%b
echo 『我的文档』
if "%MD%*"=="*" set MD=%USERPROFILE%\My Documents
echo %MD%
for /f "tokens=3*" %%a in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Music" ^|findstr "Music"') do @set MM=%%b
echo 『我的音乐』
if "%MM%*"=="*" set MM=%USERPROFILE%\My Documents\My Music
echo %MM%
for /f "tokens=3*" %%a in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Video" 2^>nul^|findstr "Video"') do @set MV=%%b
echo 『我的视频』
if "%MV%*"=="*" set MV=%USERPROFILE%\My Documents\My Videos
echo %MV%
for /f "tokens=3*" %%a in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Pictures" ^|findstr "Pictures"') do @set MP=%%b
echo 『图片收藏夹』
if "%MP%*"=="*" set MP=%USERPROFILE%\My Documents\My Pictures
echo %MP%
for /f "tokens=2*" %%a in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Favorites ^|findstr "Favorites"') do @set F=%%b
echo 『收藏夹』
if "%F%*"=="*" set F=%USERPROFILE%\Favorites
echo %F%
:: 传真
:: HKLM\SOFTWARE\Microsoft\Fax
:: HKLM\SOFTWARE\Microsoft\Fax\ActivityLogging
:: DBFile=%ALLUSERSPROFILE%\Application Data\Microsoft\Windows NT\MSFax\ActivityLog
:: HKLM\SOFTWARE\Microsoft\Fax\Inbox
:: Folder=%ALLUSERSPROFILE%\Application Data\Microsoft\Windows NT\MSFax\Inbox
:: HKLM\SOFTWARE\Microsoft\Fax\SentItems
:: Folder=%ALLUSERSPROFILE%\Application Data\Microsoft\Windows NT\MSFax\SentItems
::
for /f "tokens=2*" %%a in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Cache ^|findstr "Temporary"') do @set Ca=%%b
echo 『Cache』
if "%Ca%*"=="*" set Ca=%USERPROFILE%\Local Settings\Temporary Internet Files
echo %Ca%
for /f "tokens=2*" %%a in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Cookies ^|findstr "Cookies"') do @set Co=%%b
echo 『Cookies』
if "%Co%*"=="*" set Co=%USERPROFILE%\Cookies
echo %Co%
for /f "tokens=2*" %%a in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v History ^|findstr "History"') do @set H=%%b
echo 『History』
if "%H%*"=="*" set H=%USERPROFILE%\Local Settings\History
echo %H%
for /f "tokens=2 delims={}" %%a in ('REG QUERY HKCU\Identities /v "Default User ID" 2^>nul^|findstr /i "Default"') do @set O=%%a
for /f "tokens=3*" %%a in ('REG QUERY "HKCU\Identities\{%O%}\Software\Microsoft\Outlook Express\5.0" /v "Store Root" 2^>nul^|findstr "Store"') do @set OE=%%b
echo 『Outlook Express』
if "%OE%*"=="*" set OE=%USERPROFILE%\Local Settings\Application Data\Identities\{88888888-8888-8888-8888-888888888888}\Microsoft\Outlook Express\\
echo %OE%
for /f "tokens=2*" %%a in ('REG QUERY "HKCU\Environment" /v TEMP ^|findstr "TEMP"') do @set T=%%b
echo 『TEMP』
if "%T%*"=="*" set T=%%USERPROFILE%%\Local Settings\Temp
echo %T%
echo.
set /P OK="请输入一个指令或目标驱动器:[H | Q | U | drive:] "
if "%OK%"=="h" set h=1&&goto help
if "%OK%"=="H" set h=1&&goto help
if "%OK%"=="q" echo.&&echo 正在退出. . .&&call :ProcDelay 200&&goto end
if "%OK%"=="Q" echo.&&echo 正在退出. . .&&call :ProcDelay 200&&goto end
if "%OK%"=="u" goto original
if "%OK%"=="U" goto original
if not exist %OK%\nul goto input
if exist "%MD%\nul" xcopy "%MD%\*.*" "%OK%\My Documents" /i /q /h /r /y >nul 2>nul
if exist "%Co%\nul" xcopy "%Co%\*.*" "%OK%\My Documents\Cookies" /s /i /q /h /r /y >nul 2>nul
if exist "%F%\nul" xcopy "%F%\*.url" "%OK%\My Documents\Favorites" /s /i /q /h /r /y >nul 2>nul
if exist "%H%\nul" xcopy "%H%\*.*" "%OK%\My Documents\History" /s /i /q /h /r /y >nul 2>nul
if exist "%MM%\nul" xcopy "%MM%\*.*" "%OK%\My Documents\My Music" /s /i /q /h /r /y >nul 2>nul
if exist "%MP%\nul" xcopy "%MP%\*.*" "%OK%\My Documents\My Pictures" /s /i /q /h /r /y >nul 2>nul
if exist "%MV%\nul" xcopy "%MV%\*.*" "%OK%\My Documents\My Videos" /s /i /q /h /r /y >nul 2>nul
if exist "%OE%\nul" xcopy "%OE%\*.*" "%OK%\My Documents\Outlook Express" /s /i /q /h /r /y >nul 2>nul
if exist "%Ca%\nul" xcopy "%Ca%\*.*" "%OK%\My Documents\Temporary Internet Files" /s /i /q /h /r /y >nul 2>nul
reg delete "HKCU\Identities\{%O%}" /f>nul
reg add "HKCU\Environment" /v "TEMP" /t REG_EXPAND_SZ /d "%OK%\My Documents\Temp" /f>nul
reg add "HKCU\Environment" /v "TMP" /t REG_EXPAND_SZ /d "%OK%\My Documents\Temp" /f>nul
reg add "HKCU\Identities" /v "Default User ID" /t REG_SZ /d "{88888888-8888-8888-8888-888888888888}" /f>nul
reg add "HKCU\Identities" /v "Last User ID" /t REG_SZ /d "{88888888-8888-8888-8888-888888888888}" /f>nul
reg add "HKCU\Identities\{88888888-8888-8888-8888-888888888888}" /v "User ID" /t REG_SZ /d "{88888888-8888-8888-8888-888888888888}" /f>nul
reg add "HKCU\Identities\{88888888-8888-8888-8888-888888888888}\Software\Microsoft\Outlook Express\5.0" /v "Store Root" /t REG_EXPAND_SZ /d "%OK%\My Documents\Outlook Express\\" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Cache" /t REG_SZ /d "%OK%\My Documents\Temporary Internet Files" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Cookies" /t REG_SZ /d "%OK%\My Documents\Cookies" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Favorites" /t REG_SZ /d "%OK%\My Documents\Favorites" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "History" /t REG_SZ /d "%OK%\My Documents\History" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Music" /t REG_SZ /d "%OK%\My Documents\My Music" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Pictures" /t REG_SZ /d "%OK%\My Documents\My Pictures" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Video" /t REG_SZ /d "%OK%\My Documents\My Videos" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Personal" /t REG_SZ /d "%OK%\My Documents" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Cache" /t REG_EXPAND_SZ /d "%OK%\My Documents\Temporary Internet Files" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Cookies" /t REG_EXPAND_SZ /d "%OK%\My Documents\Cookies" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Favorites" /t REG_EXPAND_SZ /d "%OK%\My Documents\Favorites" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "History" /t REG_EXPAND_SZ /d "%OK%\My Documents\History" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Pictures" /t REG_EXPAND_SZ /d "%OK%\My Documents\My Pictures" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Personal" /t REG_EXPAND_SZ /d "%OK%\My Documents" /f>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths" /v "Directory" /t REG_SZ /d "%OK%\My Documents\Temporary Internet Files\Content.IE5" /f>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\path1" /v "CachePath" /t REG_SZ /d "%OK%\My Documents\Temporary Internet Files\Content.IE5\Cache1" /f>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\path2" /v "CachePath" /t REG_SZ /d "%OK%\My Documents\Temporary Internet Files\Content.IE5\Cache2" /f>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\path3" /v "CachePath" /t REG_SZ /d "%OK%\My Documents\Temporary Internet Files\Content.IE5\Cache3" /f>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\path4" /v "CachePath" /t REG_SZ /d "%OK%\My Documents\Temporary Internet Files\Content.IE5\Cache4" /f>nul
echo.
echo 文件夹内容已经复制;注册表信息已经更改,重新启动后生效!
call :ProcDelay 400
goto end
:original
reg add "HKCU\Environment" /v "TEMP" /t REG_EXPAND_SZ /d "%%USERPROFILE%%\Local Settings\Temp" /f>nul
reg add "HKCU\Environment" /v "TMP" /t REG_EXPAND_SZ /d "%%USERPROFILE%%\Local Settings\Temp" /f>nul
reg add "HKCU\Identities" /v "Default User ID" /t REG_SZ /d "{88888888-8888-8888-8888-888888888888}" /f>nul
reg add "HKCU\Identities" /v "Last User ID" /t REG_SZ /d "{88888888-8888-8888-8888-888888888888}" /f>nul
reg add "HKCU\Identities\{88888888-8888-8888-8888-888888888888}" /v "User ID" /t REG_SZ /d "{88888888-8888-8888-8888-888888888888}" /f>nul
reg add "HKCU\Identities\{88888888-8888-8888-8888-888888888888}\Software\Microsoft\Outlook Express\5.0" /v "Store Root" /t REG_EXPAND_SZ /d "%USERPROFILE%\Local Settings\Application Data\Identities\{88888888-8888-8888-8888-888888888888}\Microsoft\Outlook Express\\" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Cache" /t REG_SZ /d "%USERPROFILE%\Local Settings\Temporary Internet Files" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Cookies" /t REG_SZ /d "%USERPROFILE%\Cookies" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Favorites" /t REG_SZ /d "%USERPROFILE%\Favorites" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "History" /t REG_SZ /d "%USERPROFILE%\Local Settings\History" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Music" /t REG_SZ /d "%USERPROFILE%\My Documents\My Music" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Pictures" /t REG_SZ /d "%USERPROFILE%\My Documents\My Pictures" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "My Video" /t REG_SZ /d "%USERPROFILE%\My Documents\My Videos" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Personal" /t REG_SZ /d "%USERPROFILE%\My Documents" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Cache" /t REG_EXPAND_SZ /d "%%USERPROFILE%%\Local Settings\Temporary Internet Files" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Cookies" /t REG_EXPAND_SZ /d "%%USERPROFILE%%\Cookies" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Favorites" /t REG_EXPAND_SZ /d "%%USERPROFILE%%\Favorites" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "History" /t REG_EXPAND_SZ /d "%%USERPROFILE%%\Local Settings\History" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "My Pictures" /t REG_EXPAND_SZ /d "%%USERPROFILE%%\My Documents\My Pictures" /f>nul
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders" /v "Personal" /t REG_EXPAND_SZ /d "%%USERPROFILE%%\My Documents" /f>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths" /v "Directory" /t REG_SZ /d "%USERPROFILE%\Local Settings\Temporary Internet Files\Content.IE5" /f>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\path1" /v "CachePath" /t REG_SZ /d "%USERPROFILE%\Local Settings\Temporary Internet Files\Content.IE5\Cache1" /f>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\path2" /v "CachePath" /t REG_SZ /d "%USERPROFILE%\Local Settings\Temporary Internet Files\Content.IE5\Cache2" /f>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\path3" /v "CachePath" /t REG_SZ /d "%USERPROFILE%\Local Settings\Temporary Internet Files\Content.IE5\Cache3" /f>nul
reg add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\Cache\Paths\path4" /v "CachePath" /t REG_SZ /d "%USERPROFILE%\Local Settings\Temporary Internet Files\Content.IE5\Cache4" /f>nul
echo.
echo 注册表信息已经恢复,重新启动后生效!
call :ProcDelay 400
goto end
:help
if "%h%"=="1" echo.
echo 复制并转移系统资料文件夹。
echo.
echo DATAMOVE [drive:] [/U] [/Q] [/H]
echo.
echo   drive:  指定您想转移到的目标驱动器
echo   /U      恢复系统默认值
echo   /Q      向导中退出
echo   /H      显示帮助信息
echo.
echo 不加任何参数键入 DATAMOVE,可以启动一个向导。
echo.
echo 目标驱动器将自动添加文件夹路径 My Documents。
echo.
echo 命令行开关 /U 会将更改过的系统注册表信息还原。
echo 它不会还原回您之前已更改系统的任何值,而直接
echo 还原回系统的默认值。
echo.
if "%h%"=="1" pause&&set h=&&goto input
goto end

:ProcDelay number
Setlocal EnableExtensions
for /f "tokens=1-4 delims=:. " %%h in ("%TIME%") do set start_=%%h%%i%%j%%k
     :wait_
     for /f "tokens=1-4 delims=:. " %%h in ("%TIME%") do set now_=%%h%%i%%j%%k
     set /a diff_=%now_%-%start_%
if %diff_% lss %1 goto wait_
Endlocal

:end
set MD=
set MM=
set MV=
set MP=
set F=
set Ca=
set Co=
set H=
set O=
set OE=
set T=
set OK=


2008-3-6 14:28
查看资料  发短消息 网志   编辑帖子  回复  引用回复
jiulong
中级用户




积分 396
发帖 183
注册 2007-12-23
状态 离线
『第 5 楼』:  

楼上的代码好恐怖呀

2008-3-7 08:49
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复

请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: