跳到主要內容

發表文章

目前顯示的是有「Batch」標籤的文章

grep & findstr 系統內建的強大文本搜尋工具

如果想找出某些含有定字串的檔案, 除了用肉眼去一個一個找之外, 還有什麼辦法呢!? 在Ubuntu 上, 使用 grep 指令 grep - r ' notepad ' . 註: -r 表示遞迴地搜尋整個資料夾包含子目錄 若是使用Windows 的作業系統, 可以使用 findstr 指令去找 findstr /s " notepad " *.* 註: /s 表示遞迴地搜尋整個資料夾包含子目錄 若是只想輸出檔案名稱, 可以加入參數 /m  如下 findstr /s /m " notepad " *.* 若是搜尋的字串中含有空白, 那我們必須加入參數 /c 使用指定字串來搜尋 列如: findstr /s /c: " notepad open " *.*

[Windows Batch]Net use 無法使用

"不允許使用多於一個使用者名稱的相同使用者有多個連線到一個伺服器或共用資源。 中斷所有之前到伺服器或共用資源的連線,然後再試。" 連續使用以下指令卻跑出以上的錯誤訊息 net use \\10.36.174.101\Samba "$RDF^" /USER:Andy =====COPY File===== net use \\10.36.174.101\Samba2 "$RDF^" /USER:Andy =====COPY File===== 解決方法很簡單: 只要在使用完 net use  後, 執行指令 /delete 去釋放網路資源就可以解決 net use \\10.36.174.101\Samba "$RDF^" /USER:Andy =====COPY File===== net use \\10.36.174.101\Samba  /delete net use \\10.36.174.101\Samba2 "$RDF^" /USER:Andy =====COPY File===== net use \\10.36.174.101\Samba2   /delete

How to remove a substring via batch command

Here is a tip to remove a substring via batch command For example: If I'd like to remove file extension name  from  Install .wim to  Install We can try below command: Test.cmd SET WINPE=%1 echo %WINPE% SET WINPE=%WINPE:.wim=% echo %WINPE% Input:  Test.cmd Install.wim Output:  Install REF: http://www.dostips.com/DtTipsStringManipulation.php

[Batch][loop] Recurse find specified file and do something

Assume you need to update many  Setting.xml  in the specified directory and they locate on different sub-folders. You can copy&past one-by-one if you have a lot of time to do this. Or you can try below batch script:  SET FileName ="C:\Users\Andy\Dropbox\ Setting.xml " FOR /F  "usebackq delims==" %%i IN (`dir /b /s Setting.xml `) DO COPY /Y  %FileName% "%%i"