D:\>cd mysql D:\mysql>cd /d C:/TEMP C:\Temp>cd /? 顯示當前目錄名或改變當前目錄。 CHDIR [/D] [drive:][path] CHDIR [..] CD [/D] [drive:][path] CD [..] .. 指定要改爲父目錄。 鍵入 CD drive: 顯示指定驅動器中的當前目錄。 不帶參數只鍵入 CD,則顯示當前驅動器和目錄。 使用 /D 開關,除了改變驅動器的當前目錄以外, 還可改變當前驅動器。 若是命令擴展被啓用,CHDIR 會以下改變: 當前的目錄字符串會被轉換成使用磁盤名上的大小寫。因此, 若是磁盤上的大小寫如此,CD C:\TEMP 會將當前目錄設爲 C:\Temp。 CHDIR 命令不把空格看成分隔符,所以有可能將目錄名改成一個 帶有空格但不帶有引號的子目錄名。例如: cd \winnt\profiles\username\programs\start menu 與下列相同: cd "\winnt\profiles\username\programs\start menu" 在擴展停用的狀況下,你必須鍵入以上命令。 C:\Temp>cd
md IBM\SPSS\Modeler\18.0\python
https://blog.csdn.net/baidu_26408419/article/details/78885206?utm_source=blogxgwz0mysql
taskkill /f /im Explorer.exe (關閉Explorer.exe進程) 算法
通常就用@remsql
1).echo表示顯示此命令後的字符shell
echo 有這個echo就能夠把後面的語句打印出來了 pause
2.)echo off表示在此語句後全部運行的命令都不顯示命令行自己windows
echo 有這個echo就能夠把後面的語句打印出來了 echo off echo 有echo off後後面全部的命令都不顯示命令行自己 pause
3)@與echo off相象,但它是加在每一個命令行的最前面,表示運行時不顯示這一行的命令行(只能影響當前行)緩存
@echo 有@當前行的命令不顯示命令行自己 pause
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("%~fs0 h",0)(window.close)&&exitbash
案列1:查看系統信息spa
@echo off if "%1" == "h" goto begin mshta vbscript:createobject("wscript.shell").run("%~fs0 h",0)(window.close)&&exit :begin @echo off start devmgmt.msc start dxdiag.exe start taskmgr.exe
案列2:打開網頁,查看磁盤信息操作系統
@echo off if "%1" == "h" goto begin mshta vbscript:createobject("wscript.shell").run("%~fs0 h",0)(window.close)&&exit :begin @echo off start www.ip138.com start diskmgmt.msc
以前的資料:
dos 批處理命令(forfiles)
Windows Server 2003內置的命令行文件,不適合於XP系統
1. 用批處理文件刪除當前目錄下 7 天之前的擴展名爲bkf文件(以當前系統時間爲基準)
示例: forfiles /m *.bkf /d -7 /c "cmd /c del @file /f"
2. forfiles 自動刪除7天前文件 (以當前系統時間爲基準)
示例: forfiles /p "d:\test" /s /m *.* /d -7 /c "cmd /c del @path"
d:\test換成你要的目錄路徑; /d -7 指刪除7天之前文件。
3. 刪除全部的空目錄(以刪除d:\test目錄下爲例) :
dir /ad/b/s d:\test\ |sort /r >d:\kill.txt
For /f "tokens=*" %%i in (d:\kill.txt) DO rd "%%i"
del d:\kill.txt
4. 先刪7 天之前文件,再刪全部的空目錄 ;把如下複製到bat文件中。
@echo off
forfiles /p "d:\test" /s /m *.* /d -7 /c "cmd /c del @path"
dir /ad/b/s d:\test\ |sort /r >d:\kill.txt
For /f "tokens=*" %%i in (d:\kill.txt) DO rd "%%i"
del d:\kill.txt
5. forfiles 命令的用法及參數:
forfiles /p <目標目錄名> /d <天數> /c <執行的命令>
/p 指定了要在哪一個目錄裏查找文件,默認是當前工做目錄。
/d 指定一個日期或天數,用於比較文件的最後修改日期是否符合條件。
/c 對每一個找到的文件執行的命令。
例1.要把在C盤根目錄下最後修改日期大於或等於2010年1月7日的文件複製到D盤根目錄下:
forfiles /p "c:\" /d "2007-7-1" /c "cmd /c copy @path d:\"
例2.刪除在C盤backup目錄下最後修改日期在10天前的文件:
forfiles /p "c:\backup" /d -10 /c "cmd /c echo deleting @file ... && del /f @path"
6. forfiles /p 包含要刪除文件的完整路徑(如:F:\Logfiles) /m *.log -d -7 /c "cmd /c del /f
@path"
解釋一下相關參數及命令
/p <Path> : 指定開始搜索文件的位置,若是不指定則默認爲當前目錄。
/m <SearchMask> : 文件查找所使用的通配符如代碼中的"*.log"則爲全部日誌文件,固然也能夠指定諸
如"manmee_*.log"這樣以manmee開頭的全部日誌文件。若是不指定此參數則默認爲"*.*"。
/d [{+|-}][{<Date>|<Days>}] : 指定想選擇文件的最後修改時間,上文中用了 "/d -7" 表示全部以當
天爲基礎,7天之前的文件。固然這裏還能夠指定具體時間,例如:"/d -01/7/2010"這樣全部早於2010年
1月7日的文件。注意指定的時間必須是"MM/DD/YYYY"的格式。
/c 對全部文件以此執行指定的命令,命令體須在雙引號(")內,默認是"cmd /c echo @file"。上文中用
到的是"cmd /c del /f @path"刪除指定文件。(這裏的@file 和 @path 爲變量,下文中將解釋。)
下面說一下上文中用到的參數:
@PATH : 表示文件的完整的路徑。
@File : 表示文件名稱。
接下來咱們看看刪除文件夾的操做,若是你看了上面的介紹,相信這命令你一看就能看懂。
forfiles /p 包含文件夾的路徑(如:F:\) /m 文件夾名稱(如:LogFiles) -d 0 /c "cmd /c if @ISDIR
== true rd /s/q @path"
注意這裏的"包含文件夾的路徑"不能包含要刪除的文件夾,如以上代碼所表示的就是,在F盤中查找名爲
LogFiles的文件或文件夾(不能指定查找文件夾,不過在刪除時咱們作了判斷)。
還有就是這裏出現了一個新的參數"@ISDIR"他用於判斷當前文件類型是不是"文件夾類型",若是是則爲
true不然爲false。
相信到這你們就明白了,最後再將代碼保存爲批處理文件,而後加入計劃任務按期執行便可。
看了上面的例子,以爲在 Windows Server 2003 下面要刪除老文件很簡單吧。
但若是操做系統是 Windows 2000/XP 就比較麻煩,由於它們沒有forfiles命令,只能靠本身寫批處理來
實現了。
下面是我寫的批處理文件內容:
@echo off
rem ******************************
rem * 按時間刪除文件目錄的批處理 *
rem ******************************
rem 設置臨時目錄的路徑
set tempDir=%tmp%\remove_%date:~0,10%
if not exist %tempDir% md %tempDir%
rem 設置處理日期的腳本文件的路徑
set scriptFile=%tempDir%\get_date.vbs
rem 得到要保留的天數
set days=%~1
if "%days%" == "" goto printUsage
rem 得到目標目錄的路徑
set dirPath=%~2
if "%dirPath%" == "" set dirPath=.
rem 得到要操做的文件形式
set fileSpec=%~3
if "%fileSpec%" == "" set fileSpec=*.*
rem 生成計算日期的腳本文件並得到刪除的截止日期
echo d=date()-%1 > %scriptFile%
echo s=right("0000" ^& year(d),4) ^& "-" ^& right("00" ^& month(d),2) ^& "-" ^& right("00"
^& day(d),2) >> %scriptFile%
echo wscript.echo s >> %scriptFile%
for /f %%i in ('cscript /nologo %scriptFile%') do set lastDate=%%i
rem 處理目標目錄裏的每一個對象
for /f "tokens=1,2,3* delims=<> " %%i in ('dir "%dirPath%\%fileSpec%" /a /-c /tc') do call
:proc "%%i" "%%j" "%%k" "%%l"
goto :done
rem 處理目標目錄裏對象的過程
:proc
rem 得到對象的建立日期並判斷是否爲有效格式
set fileDate=%~1
echo %fileDate% | findstr "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" > nul
if errorlevel 1 goto end
rem 得到對象的類型
set fileType=%~3
if "%fileType%" == "" goto end
rem 得到對象的名稱
set fileName=%~4
if "%fileName%" == "" goto end
if "%fileName%" == "." goto end
if "%fileName%" == ".." goto end
if "%fileName%" == "字節" goto end
if "%fileName%" == "可用字節" goto end
rem 判斷對象日期是否小於或等於刪除的截止日期
if "%fileDate:~0,10%" leq "%lastDate%" (
echo deleting "%fileName%" ...
if "%fileType%" == "DIR" ( rd /s /q "%dirPath%\%fileName%" ) else ( del /q /f "%dirPath%\%
fileName%" )
)
goto end
:error
echo An error occurred during backuping.
:done
rd /s /q %tempDir%
goto end
:printUsage
echo Usage: %0 ^<Days^> [Work directory] [Target file specification (can include wildcards)]
goto end
:end
主要是利用Windows的腳本功能來計算要刪除文件的截止日期,而後for加dir命令來提取文件的日期進行
判斷。
關於forfiles和for的詳細信息,能夠在Windows的幫助與支持中找到。
bat腳本的例子:
:: 2016-7-20 版本2.0 :: 大更新,更換統計算法,實現模塊調用 :: 支持對隱藏文件、休眠文件的斷定 :: 收集第三方大文件目錄,如www、inetpub :: 解決 超過10GB大文件,因爲32位子系統限制致使的文件精度統計 :: 2016-7-19 版本1.0 :: 一鍵統計 系統主要目錄容量,快速斷定大文件,便於工單處理 :: 以MB爲單位輸出,便於閱讀 :: 交流 EM:dingxiaoguang666@163.com @echo off&setlocal enabledelayedexpansion mode con: cols=80 lines=31 color 0a title Windows 大文件快速斷定 by:Ckey echo Windows 大文件快速斷定 set /a s=1024*1024*1024 set dir=C:\windows\syswow64 echo. echo --------------------------------- echo 文件夾:%dir% for /f "tokens=3 delims= " %%i in ('dir /s /a /-c "%dir%" ^|findstr 個文件') do (set z=%%i) call:division %z% %s% quot 2 set dir=C:\windows\winsxs echo. echo 文件夾:%dir% for /f "tokens=3 delims= " %%i in ('dir /s /a /-c "%dir%" ^|findstr 個文件') do (set z=%%i) call:division %z% %s% quot 2 set dir=C:\windows\temp echo. echo 文件夾:%dir% for /f "tokens=3 delims= " %%i in ('dir /s /a /-c "%dir%" ^|findstr 個文件') do (set z=%%i) call:division %z% %s% quot 2 set dir=%temp% echo --------------------------------- echo 文件夾:臨時文件 for /f "tokens=3 delims= " %%i in ('dir /s /a /-c "%dir%" ^|findstr 個文件') do (set z=%%i) call:division %z% %s% quot 2 echo. echo 文件夾:IE緩存 for /f "tokens=3 delims= " %%i in ('dir /s /a /-c "%dir%" ^|findstr 個文件') do (set z=%%i) call:division %z% %s% quot 2 echo. echo --------------其餘------------------- rem IF not EXIST "C:\hiberfil.sys1" (ECHO.)&PAUSE>nul&EXIT dir /A:H c:\ |findstr .sys :www IF not EXIST "C:\www" (goto int) >nul set dir=C:\www echo. echo 檢測站點目錄 %dir% for /f "tokens=3 delims= " %%i in ('dir /s /a /-c "%dir%" ^|findstr 個文件') do (set z=%%i) call:division %z% %s% quot 2 :int IF not EXIST "C:\inetpub" (goto pa) >nul set dir=C:\inetpub echo. echo 檢測站點目錄 %dir% for /f "tokens=3 delims= " %%i in ('dir /s /a /-c "%dir%" ^|findstr 個文件') do (set z=%%i) call:division %z% %s% quot 2 :pa echo. echo 檢測完畢、任意鍵退出 EM:dingxiaoguang666@163.com pause >nul :division setlocal set str1=%1 set str2=%2 if "%~4" neq "" set u=%4 for %%i in (str1 str2) do if "!%%i:~,1!" == "-" set /a d+=1 if "%d%" == "1" (set d=-) else set "d=" set l=00000000&for /l %%i in (1 1 7) do set "l=!l!!l!" set "var=4096 2048 1024 512 256 128 64 32 16 8 4 2 1" for /l %%i in (1 1 2) do ( set "str%%i=!str%%i:-=!" set /a "n=str%%i_2=0" for %%a in (!str%%i:.^= !) do ( set /a n+=1 set s=s%%a&set str%%i_!n!=0 for %%b in (%var%) do if "!S:~%%b!" neq "" set/a str%%i_!n!+=%%b&set "S=!S:~%%b!" set /a len%%i+=str%%i_!n! ) set str%%i=!str%%i:.=! ) if !str1_2! gtr !str2_2! (set /a len2+=str1_2-str2_2) else set /a len1+=str2_2-str1_2 for /l %%i in (1 1 2) do ( set str%%i=!str%%i!!l! for %%j in (!len%%i!) do set " str%%i=!str%%i:~,%%j!" ) for /f "tokens=* delims=0" %%i in ("!str2!") do set s=%%i&set "str2=0%%i" set len2=1 for %%j in (%var%) do if "!S:~%%j!" neq "" set/a len2+=%%j&set "S=!S:~%%j!" set /a len=len2+1 if !len1! lss !len2! set len1=!len2!&set "str1=!l:~-%len2%,-%len1%!!str1!" set /a len1+=u&set str1=0!str1!!l:~,%u%! set str=!str1:~,%len2%! set "i=0000000!str2!"&set /a Len_i=Len2+7 for /l %%i in (1 1 9) do ( set "T=0" for /l %%j in (8 8 !Len_i!) do ( set /a "T=1!i:~-%%j,8!*%%i+T" set Num%%i=!T:~-8!!Num%%i!&set /a "T=!T:~,-8!-%%i" ) set Num%%i=!T!!Num%%i! set "Num%%i=0000000!Num%%i:~-%Len%!" ) for /L %%a in (!len2! 1 !Len1!) do ( set "str=!L!!str!!str1:~%%a,1!" set "str=!str:~-%Len%!" if "!str!" geq "!str2!" ( set M=1&set i=0000000!str! for /l %%i in (2 1 9) do if "!i!" geq "!Num%%i!" set "M=%%i" set sun=!sun!!M!&set str=&set T=0 for %%i in (!M!) do ( for /l %%j in (8 8 !Len_i!) do ( set /a "T=3!i:~-%%j,8!-1!Num%%i:~-%%j,8!-!T:~,1!%%2" set "str=!T:~1!!str!" ) ) ) else set sun=!sun!0 ) if defined u if "%u%" gtr "0" set sun=!sun:~,-%u%!.!sun:~-%u%! endlocal&set %3=%d%%sun% echo 總大小: %quot% GB