60 likes | 218 Views
โครงสร้างคอมพิวเตอร์ และภาษาแอสเซมบลี้. Copy by Batch File. ผศ.บุรินทร์ รุจจนพันธุ์ . ปรับปรุง 1 9 ตุลาคม 2555. มหาวิทยาลัยเนชั่น จังหวัดลำปาง http://www. nation.ac.th. ทบทวนคำสั่ง DOS. @echo off rem %0 คือ Batch File Name %1 คือ First Parameter shift set และ %x%.
E N D
โครงสร้างคอมพิวเตอร์ และภาษาแอสเซมบลี้ Copy by Batch File ผศ.บุรินทร์ รุจจนพันธุ์ . ปรับปรุง 19 ตุลาคม 2555 มหาวิทยาลัยเนชั่น จังหวัดลำปาง http://www.nation.ac.th
ทบทวนคำสั่ง DOS @echo off rem %0 คือ Batch File Name %1 คือ First Parameter shift set และ %x% :label และ goto if == echo copy move cls
อธิบาย copyto.bat COPYTO.BAT ใช้สำหรับคัดลอกแฟ้มต่าง ๆ เข้าไปในห้อง c:\x แต่คำสั่ง copy ไม่มีความสามารถนี้ จำเป็นต้องเขียน Batch File มาทำหน้าที่นี้ ด้วยการอ่าน parameter ไปคัดลอกทีละแฟ้ม คำสั่งสำคัญที่ใช้คือ if label shift และ copy ตัวอย่างการใช้ copyto.bat c:\x *.doc b.ppt c.xls
copyto.bat c:\x *.doc b.ppt c.xls @echo off set destdir=%1 :start shift if "%1" == "" goto end copy %1 %destdir% goto start :end echo bye
อธิบาย mcopy.bat MCOPY.BAT ใช้สำหรับนำ parameter มาจัดเรียงใหม่ตามที่ copyto.bat ต้องการ เมื่อเรียงใส่ตัวแปร copylist แล้วก็ส่งให้ copyto.bat ทำหน้าที่คัดลอกแต่ละแฟ้มต่อไป เพราะการส่งค่าให้ mcopy.bat เริ่มจาก source ไป destination ซึ่งนิยมใช้ในคำสั่งของทุกระบบ - ต้องใช้โปรแกรม Copyto.bat- ตัวอย่างการใช้copy.bat *.doc b.ppt c.xls c:\x
mcopy.bat *.doc b.ppt c.xls c:\x @echo off set copylist= :start if "%2" == "" goto end set copylist=%copylist% %1 shift goto start :end set destination=%1 copyto %destination% %copylist%