請問批次檔怎麼寫出指定要刪除檔案的指令

Home Home
引用 | 編輯 ghost70
2006-07-18 16:54
樓主
推文 x0
我使用記事本做了一個 .bat 檔指令如下
我要刪除c:\WINDOWS\temp資料夾裡的所有檔案
包 ..

訪客只能看到部份內容,免費 加入會員



獻花 x0
引用 | 編輯 a770123
2006-07-18 18:38
1樓
  
複製程式
CLS
@ECHO OFF
ECHO.
attrib -s -h -r /s %Windir%\Temp\*.*
del /S /Q %Windir%\Temp\*.*
EXIT
大大您可以使用這樣的方式做刪除動作~~
看是不是符合您的需求!!

獻花 x1
引用 | 編輯 chang-pony
2006-07-19 17:35
2樓
  
cls 是 DOS 時代為了畫面好看,用來清除螢幕的指令,在WINDOWS是新開一個小視窗來執行批次檔,所以這個指令可以省略。
如果所要刪除的檔案很多,而不想看螢幕上顯示刪除的實況,可以將它導向:
del /S /Q %Windir%\Temp\*.* > nul

獻花 x1
引用 | 編輯 fishj07
2006-07-19 19:04
3樓
  
請問1-2樓樓主
cls 是 DOS 時代為了畫面好看,用來清除螢幕的指令
我已經知道了
而其他指令的意思?

獻花 x0
引用 | 編輯 chang-pony
2006-07-19 19:48
4樓
  
在 DOS 下鍵入 HELP,會有 DOS 指令簡介,如對單一指令有問題時,就打該指令求助,如: cls /?
因指令不少,所以請自行參考。

獻花 x0
引用 | 編輯 fishj07
2006-07-19 20:50
5樓
  
下面是引用chang-pony於2006-07-19 19:48發表的 :
在 DOS 下鍵入 HELP,會有 DOS 指令簡介,如對單一指令有問題時,就打該指令求助,如: cls /?
因指令不少,所以請自行參考。

-s -h -r /s
她沒有寫耶!!
我是有看到其他的
但是/的
沒有加以說明

獻花 x0
引用 | 編輯 冰漾
2006-07-19 22:20
6樓
  
下面是引用fishj07於2006-07-19 20:50發表的 :


-s -h -r /s
她沒有寫耶!!
我是有看到其他的
.......
那是 attrib 的參數...
請打 attrib /?

獻花 x0
引用 | 編輯 ghost70
2006-07-20 10:20
7樓
  
我又遇到問題了 我依照一樓大大說的指令做
無法刪除 C:\Documents and Settings\aaa\Local Settings\Temp 資料夾內容檔案
aaa是我的名字 Local Settings是隱藏資料夾
我用的指令是
attrib -s -h -r /s C:\Documents and Settings\aaa\Local Settings\Temp\*.*
del /S /Q C:\Documents and Settings\aaa\Local Settings\Temp\*.*

獻花 x0
引用 | 編輯 chang-pony
2006-07-20 12:54
8樓
  
請將批次檔改成:

@ echo off
c:
cd \Documents and Settings\aaa\Local Settings\Temp
attrib -s -h -r /s *.*
del /s /q *.*

PS:DOS 的指令有一個特性,中間不可以有空格,否則它會把空格後面的當成參數。

獻花 x1
引用 | 編輯 ghost70
2006-07-20 13:16
9樓
  
下面是引用chang-pony於2006-07-20 12:54發表的 :
PS:DOS 的指令有一個特性,中間不可以有空格,否則它會把空格後面的當成參數。
.......

感謝大大 測試後真的可以
但是你說中間不可以有空格 我不曉得是指哪兒不可以有空格
可再說清楚點嗎 謝謝

獻花 x0
引用 | 編輯 chang-pony
2006-07-20 16:54
10樓
  
del /S /Q C:\Documents and Settings\aaa\Local Settings\Temp\*.*
以上面指令為例:
DOS 的解讀是:
del /S /Q C:\Documents 而把此後面全當成參數( and Settings\aaa\Local Settings\Temp\*.*),所以就出現錯誤而無法執行。

但此指令也可以改成:
del /S /Q "C:\Documents and Settings\aaa\Local Settings\Temp\*.*"
結果相同。

獻花 x0
引用 | 編輯 莫力思雷靠唄
2006-07-20 18:42
11樓
  
有需要把 C:\Documents and Settings\aaa\Local Settings\Temp\*.* 寫的那麼複雜嗎???
為什麼不把它簡易成 %Temp%\*.*

獻花 x0
引用 | 編輯 冰漾
2006-07-20 23:06
12樓
  
下面是引用莫力思雷靠唄於2006-07-20 18:42發表的 :
有需要把 C:\Documents and Settings\aaa\Local Settings\Temp\*.* 寫的那麼複雜嗎???
為什麼不把它簡易成 %Temp%\*.*
是滴...
為了避免錯誤, 請大家使用『環境變數』:
http://forum.shareget.com/showthread.php?t=287801

獻花 x0
引用 | 編輯 ghost70
2006-07-21 16:01
13樓
  
感謝...我了解了.......

獻花 x0
引用 | 編輯 mingchau
2006-07-28 18:13
14樓
  
這是我現時用的方法,比較簡單 表情
將以下複制,副檔為.cmd (Windows XP) 或 .bat。
@ECHO OFF
rd /s /q "%userprofile%\Local Settings\Temp" & md "%userprofile%\Local Settings\Temp" > nul

獻花 x0
引用 | 編輯 pcf88
2006-08-10 20:37
15樓
  
以下是我個人所用.大家可以試試:
檔案名:xxx.bat
-----------------------------------------------------------------------------
@echo off
rd /s /q %windir%\temp & md %windir%\temp
del /f /s /q %userprofile%\Local Settings\Temp\*.*
rmdir /s/q   %userprofile%\Local Settings\Temp\
exit
------------------------------------------------------------------------------
表情 表情

獻花 x0
引用 | 編輯 allenwl
2008-09-13 12:28
16樓
  
@echo off
Echo 清除系統暫存垃圾中...
for %%a in (%tmp%\ %temp%\ %windir%\temp\ %windir%\Prefetch\ "%userprofile%\Cookies\" "%userprofile%\Recent\" "%userprofile%\Application Data\Microsoft\Office\Recent\" "%userprofile%\Local Settings\Temp\" "%userprofile%\Local Settings\Temporary Internet Files\Content.IE5\") do del %%a /f /s /q

獻花 x0
引用 | 編輯 gigamark
2008-10-27 23:59
17樓
  
建議你用 total commander
或者用cclean
也可以清楚一些暫存檔,
簡單, 直覺, 好用

基本上 批次檔 是一種命令語言,
需要學習,
幾句話要回答,
很難...................

獻花 x0