基本上我想要echo "test" >> file.txt
,直到file.txt達到像2MB一定的大小,這可能嗎?批量增加大小,直到大小符合
0
A
回答
0
腳本會將「測試」回顯到file.txt,直到它大於2 MB。雖然批處理對於這樣的事情來說很慢......您可以在大塊中回顯更多文本。像echo.test試驗試驗試驗試驗試驗
@echo off
setlocal enabledelayedexpansion
set filename="file.txt"
rem 2097152 bytes=2 MB
set maxbytesize=2097152
:lop
for /F %%a IN (%filename%) do set size=%%~za
if !size! LSS %maxbytesize% (
echo.test>>%filename%
goto :lop
)
0
可惜的是,批次算術是有限的,使用該方法,以便最大文件長度被限制爲2^31-1字節文件(2GB)。無論如何,這應該是足夠快的可用性(2MB文件少於一秒)。
@echo off
setlocal enableextensions enabledelayedexpansion
set /a "size=1024*1024*2"
set "file=grow.txt"
set "tempFile=%temp%\%~nx0.%random%.tmp"
<nul set /p "x=." > "%tempFile%"
break > "%file%"
set "cmd=type"
for /l %%n in (1 1 31) do if defined size (
if %%n equ 22 (set "cmd=findstr ""^"" ")
set /a "first=size & 1" & if !first! equ 1 !cmd! "%tempFile%" >> "%file%"
set /a "size>>=1" & if !size! gtr 0 (!cmd! "%tempFile%" >> "%tempFile%") else set "size="
)
del "%tempFile%" >nul 2>nul
endlocal
並與評論
@echo off
setlocal enableextensions enabledelayedexpansion
:: Configure size and file to generate
set /a "size=1024*1024*2"
set "file=grow.txt"
:: Prepare a 1 byte temporary file
set "tempFile=%temp%\%~nx0.%random%.tmp"
<nul set /p "x=." > "%tempFile%"
:: Initialize the output file
break > "%file%"
:: To move data, type command is used for the 21 first
:: rounds, as it is more "efficient" for small sizes as
:: it does not have the overhead of creating a new process.
:: From this point, findstr replaces type command. The
:: overhead of creating the process is negligible vs the
:: speed on data transfer.
set "cmd=type"
:: Generate the final file, checking the bits in the
:: indicated size to determine how and when to add
:: data to the file.
echo %time%
for /l %%n in (1 1 31) do if defined size (
if %%n equ 22 (set "cmd=findstr ""^"" ")
set /a "first=size & 1" & if !first! equ 1 !cmd! "%tempFile%" >> "%file%"
set /a "size>>=1" & if !size! gtr 0 (!cmd! "%tempFile%" >> "%tempFile%") else set "size="
)
echo %time%
:: Show generated file information
echo.
dir "%file%" | findstr /r /c:"^[0-9]"
echo.
:: cleanup
del "%tempFile%" >nul 2>nul
endlocal
就根據這一概念的解釋同樣看到Ancient Egyptian Multiplication
相關問題
- 1. 在SOQL中增加批量大小
- 2. 增加大小
- 3. 增加大小
- 4. 增加大小
- 5. Imagemagick大量增加文件大小?
- 6. Facebook批量大小
- 7. D3.js直方圖bin大小增量
- 8. 增加堆大小
- 9. 增加sc_fifo_out大小
- 10. 當我增加圖像大小時td大小不會增加
- 11. 增加交換大小如何增加堆大小?
- 12. OCAML增量搜索子字符大小
- 13. Elasticsearch hadoop配置批量批量大小
- 14. 批量大小 - Lambda/Kinesis
- 15. elasticsearch java批量大小
- 16. NHibernate和批量大小
- 17. sql azure批量大小
- 18. 優化批量大小
- 19. nhibernate替代批量大小
- 20. 批量調整大小
- 21. Hibernate批量大小混淆
- 22. 增量大小表格內
- 23. 命題調整圖像大小,直到符合所需的文件大小
- 24. 如何增加矢量大小?
- 25. CSS最小高度+增量大小
- 26. UIImagePNGRepresentation增加輸出文件大小而不是減小大小
- 27. 增加任務大小spark
- 28. 增加J48樹大小weka
- 29. Extjs:增加JsonStore的大小
- 30. 增加節點大小vis.js
這是可能的... –
大聲笑我怎麼辦呢?我總共n00b – user3244451
有一定的耐心......;) –