2011-08-30 18 views
25

可能重複:
Windows version of the Unix touch command如何使用標準Windows命令觸摸文件?

我需要用理智最多別的重現好老touch hello.c但標準的Windows命令。

我想這

copy /y nul empty.txt 
copy /b /y empty.txt+hello.c hello.c 

但文件hello.c不會改變。

如何更改文件的日期,但不更改其內容,除了標準Windows XP Pro安裝(CMD,FIND,SORT等)中提供的內容外,其他內容除外?

+1

不是重複,因爲這問題問的端口(並且因爲這個問題被關閉了),而這個問題詢問如何_simulate_命令。如果我有代表,我會投票重新開放。 – SQB

+0

嘗試鍵入NUL>%1(如果您使用的是批處理文件)或鍵入NUL> file.ext –

+0

爲什麼Redmond不在Windows中添加'touch'命令? –

回答

26

打開CMD做到這一點(以管理員身份運行)。該命令會將文件的日期和時間戳更改爲當前。

copy <<filename.extn>> /B+ ,,/Y 

如果你想要做一個目錄批量變化,比如說,所有的gif文件,然後

for %i in ('dir *.gif') do copy %i /B+ ,,/Y 

Reference - http://www.sprint.net.au/~terbut/usefulbox/msdoscmds.htm

+5

從其他目錄發佈時,對我無效。最終使用:'copy/by filename.extn + nul filename.extn' – sthlm58

+0

@ sthlm58,你可以嘗試'pushd'和'popd'臨時切換。 – Synetech

+0

對我來說,我不得不刪除'標記。這工作: '爲%i在(dir * .gif)做副本%i/B + ,,/Y' – dslake

9

注:我意識到這個答案沒有解決這個問題。 OP不要求創建文件,而是更新修改後的元數據。

copy con hello.c會把你帶入詳細輸入模式,也可以使用type nul >>hello.c創建一個空文件(如果hello.c尚不存在)

14

可以使用

copy /b "file name" +,, 
+0

你能詳細說明這是什麼嗎? – Marc

+0

https://blogs.msdn.microsoft.com/oldnewthing/20130710-00/?p=3843 – Bernhard