Windows批處理中擷取檔案屬性的一些方法_DOS/BAT

來源:互聯網
上載者:User

windows的batchfile可以有%0-%9參數,其中%0預設表示batchfile的全路徑,%1-%9為使用者的傳入參數。

以下特殊標記可以用來獲得檔案的屬性,如果對%0使用特殊標記,表示獲得batachfile的相關屬性,如果%1-%9中某個%*是個檔案的路徑,也可以使用如下特殊標記來獲得%*表示檔案的相關屬性。

例如:D:\testfolder\test.bat

複製代碼 代碼如下:

echo off
echo path name:
echo %1
echo fully qualified path name:
echo %~f1
echo dirive:
echo %~d1
echo path:
echo %~p1
echo name:
echo %~n1
echo extention:
echo %~x1
echo short name:
echo %~s1
echo attribute:
echo %~a1
echo time:
echo %~t1
echo size:
echo %~z1
echo directory:
echo %~dp1

調用時為D:\testfolder\test.bat "c:\test\new folder\mytable.txt",輸出如下:

複製代碼 代碼如下:

D:\>echo off
path name:
"c:\test\new folder\mytable.txt"
fully qualified path name:
c:\test\New Folder\mytable.txt
dirive:
c:
path:
\test\New Folder\
name:
mytable
extention:
.txt
short name:
c:\test\NEWFOL~1\mytable.txt
attribute:
--a------
time:
2010-09-27 15:01
size:
directory:
c:\test\New Folder\

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.