• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            eryar

            PipeCAD - Plant Piping Design Software.
            RvmTranslator - Translate AVEVA RVM to OBJ, glTF, etc.
            posts - 603, comments - 590, trackbacks - 0, articles - 0

            Iterate Files by Tcltk

            Posted on 2015-01-18 12:08 eryar 閱讀(1930) 評論(0)  編輯 收藏 引用 所屬分類: 2.OpenCASCADE6.Others

            Iterate Files by Tcltk

            eryar@163.com

            Abstract. Tcl/Tk provide a programming system for developing and using graphical user interface(GUI) applications. Tcl stands for “tool command language” and is pronounced “tickle”, is a simple scripting language for controlling the extending applications. The blog use Tcl/Tk to iterate all the files for a given directory, this is useful to some automation work, such as change all the file names for a given directory; add copyright info for the source code files.

            Key Words. Tcl/Tk, Iterate Files,遍歷文件夾中所有文件

            1. Introduction

            Tcl/Tk是一種用于易于使用的腳本語言,可以用來對程序進行擴展及完成一些自動化的工作,加上內置的一些命令,其功能要比Windows中的DOS的批處理命令功能更強大,使用更方便。Tcl腳本語言是開源免費的,可以方便獲取且免費使用。

            OpenCASCADE中使用了Tcl/Tk來實現了一個自動化測試體系。使用在OpenCASCADE中使用自定義的Tcl命令,可以快速來檢驗算法的結果。通過編寫腳本文件,實現了測試的自動化。所以學習一下Tcl/Tk腳本語言,并在實際的工作中加以應用,可以將一些機械的勞動交給計算機自動完成。

            本文主要說明如何使用Tcl/Tk來遍歷指定文件夾中所有文件。利用此功能,可以稍微加以擴展,就可以完成一些實際的重復勞動。如遍歷指定目錄中所有的源文件或指定類型的文件,添加上版權信息等。

            2. Tcl/Tk Code

            要遍歷指定目錄下所有的文件,包括子文件夾,需要用到命令glob及一個遞歸函數。腳本代碼如下所示:

            #
            # Tcl/Tk script to iterate all the files for a given directory.
            # eryar@163.com
            # 2015-01-18
            #


            package require Tcl
            package require Tk

            wm title 
            . "Iterate Files"

            label 
            .labelDirectory -text "Directory "
            entry 
            .entryDirectory -width 30 -relief sunken -textvariable aDirectory
            button 
            .buttonDirectory -text "" -command {chooseDirectory .entryDirectory}

            button 
            .buttonApply -text "Apply" -command {perform $aDirectory}
            button 
            .buttonCancel -text "Cancel" -command {exit}

            grid 
            .labelDirectory .entryDirectory .buttonDirectory
            grid 
            .buttonApply .buttonCancel

            # chooseDirectory--
            # choose the directory to iterate.

            proc chooseDirectory {theEntry} {
                set dir [tk_chooseDirectory 
            -initialdir [pwd] -mustexist 1]
                
                
            if {[string compare $dir ""]} {
                    
            $theEntry delete 0 end
                    
            $theEntry insert 0 $dir
                    
            $theEntry xview end
                }
            }

            # perform--
            # perform the algorithm.
            #

            proc perform {theDirectory} {
                puts 
            "Iterate all the files in $theDirectory"
                
                
            if {[string length $theDirectory< 1} {
                    tk_messageBox 
            -type ok -icon warning -message "Please select the directory!" -parent .
                    
            return 
                }
                
                
            # process the iterate
                process $theDirectory
            }

            # process--
            # recursion every folder and file.
            #

            proc process {theFolder} {

                set aFiles [
            glob -nocomplain -directory $theFolder *]
                
                
            foreach aFile $aFiles {
                    
            if {[file isfile $aFile]} {
                        
            # just output the file name here. 
                        # you can do something such as rename for the file.

                        puts "$aFile \n"
                    } 
            else {
                        process 
            $aFile
                    }
                }
            }

            程序用法為打開Tcl解釋器,使用命令source加載腳本文件,如下圖所示:

            wps_clip_image-20196

            Figure 2.1 Tcl usage

            3. Conclusion

            通過應用Tcl/Tk來體驗腳本編程的樂趣,并加深對Tcl/Tk的理解。從而對OpenCASCADE的模塊Draw Test Harness更好地理解。

            如果有編程基礎,Tcl/Tk會很快入門的。入門后,可以應用其直接編寫一些有意思有腳本,來實現一些重復工作的自動化。也可將Tcl加入到自己的程序中,增加程序的二次開發功能。

            可見,玩一玩腳本語言,還是非常有趣的!


            PDF Version and Script: Iterate Files by Tcl

            av无码久久久久不卡免费网站 | 久久久免费精品re6| 久久99热这里只有精品国产| 久久久国产亚洲精品| 久久午夜伦鲁片免费无码| 国产精品久久久久天天影视| 久久精品国产亚洲一区二区三区| 色偷偷91久久综合噜噜噜噜| 亚洲午夜久久久久久噜噜噜| 91精品免费久久久久久久久| 久久国产精品无| 天天久久狠狠色综合| 午夜精品久久久久久影视777 | 伊人久久免费视频| 久久婷婷色香五月综合激情| 久久天天躁狠狠躁夜夜网站| 精品久久人人妻人人做精品| 色欲久久久天天天综合网精品| 久久成人精品| 国产精品青草久久久久婷婷| 三级三级久久三级久久| 久久99精品国产麻豆不卡| 91久久精一区二区三区大全| 精品久久久无码21p发布| 岛国搬运www久久| 狠狠色婷婷综合天天久久丁香| 美女久久久久久| 理论片午午伦夜理片久久 | 国内精品九九久久精品| 久久久久综合国产欧美一区二区 | 久久精品国产日本波多野结衣| 精品久久久久久| 国产韩国精品一区二区三区久久| 一本一本久久a久久综合精品蜜桃| 久久精品国产第一区二区| 狠狠精品久久久无码中文字幕| 国内精品久久人妻互换| 精品无码久久久久久尤物| 国产精品九九九久久九九| 青青国产成人久久91网| 伊人久久免费视频|