2017-03-01 23 views
1

我已經批量創建了一個撲克遊戲來顯示.txt文件中的卡片。我使用下面的代碼來顯示它們。將文本從txt文件並行批量顯示?

if %color% == orange type %card%of%suit%.txt & type %cardd%of%suitt%.txt 

這正常比卡之外都顯示爲一個在另一個的上面是這樣的:

.------. 
|A /\ | 
|/\ | 
| \/| 
| \/ A| 
^------^ 
.------. 
|A /\ | 
|/\ | 
| \/| 
| \/ A| 
^------^ 

我想並排顯示的卡面是這樣的:

.------. .------. 
|A /\ | |A /\ | 
|/\ | |/\ | 
| \/| | \/| 
| \/ A| | \/ | 
^------^ ^------^ 

提前致謝!

+0

This answer http:// stackoverflow。com/questions/42500455 /批處理文件合成文本從多個文件到一個csv/42501797#42501797可以很容易地適應您的願望 – Magoo

+0

對不起,因爲如此無知,但你能告訴我如何Magoo?我不明白這種情況怎麼可能被採用? – JohnBatch

回答

2

我稍微修改了代碼,在this answer來解決這個問題,就是在這種情況下,更簡單,因爲所有文件都具有相同的行數:

@echo off 
setlocal EnableDelayedExpansion 

rem Example of use: 
call :showCards %card%of%suit%.txt %cardd%of%suitt%.txt %carddd%of%suittt%.txt 
goto :EOF 


:showCards 

rem Copy first card 
copy %1 allCards.txt > NUL 

:nextCard 
shift 
if "%~1" equ "" goto endCards 

move /Y allCards.txt allCards.in > NUL 

(
    rem Read lines of previous cards from Stdin 
    rem and combine they with this card 
    < allCards.in (for /F "usebackq delims=" %%l in ("%~1") do (
     set /P "line=" 
     echo !line! %%l 
    )) 

rem Combine previous output in new output file 
) > allCards.txt 

goto nextCard 
:endCards 

type allCards.txt 
exit /B 

需要注意的是一個小的修改是必要的情況下,該字符中使用的字符包括!感嘆號或^插頁。

1

使用batch file combine text from multiple files into one csv

sourcedir是方含您%card%of%suit%.txt文件的目錄。這可能是.或者如果它是當前目錄,則完全省略。

destdir你並不需要,因爲它是一個輸出目錄

不指定分配給card什麼值 - 大概card1..card5(不限),所以現在我猜。文件列表將

%card1%of%suit1%.txt %card2%of%suit2%.txt %card3%of%suit3%.txt %card4%of%suit4%.txt %card5%of%suit5%.txt ..... 

既然說,如果card5是未分配的,這將產生一個不存在的文件名,然後for %%f....) do IF EXIST findstr ...到門時的findstr如果該文件不存在。

maxline可能是一個常量(文件中的行數應該全部相同並且已知),因此可以直接指定它,並且可以省略指定值的for ...%%a

由於您不是產生一個輸出文件,其包圍FOR /L環路()>"outfile%"和需要被省略 - 其結果是在echo將被引導到屏幕爲正常。

當通過追加%%b來構建線條時,您可能需要在!%%b之間插入一個空格。如果你這樣做,line將收購領先的空間首先是加時,所以你可能想要刪除前導空格,可以通過echo完成荷蘭國際集團!line:~1!

所以 - 簡單,有條不紊的調整。我使用了5張#牌,但原則上沒有限制 - 只有可用的屏幕寬度。

+0

變量%card%和%suit%是隨機生成的我已經創建了52個txt文件,其中包含「圖形」。我不知道這是否是有用的信息,但這個答案似乎太複雜了,我的目的 – JohnBatch

相關問題