• <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) 評(píng)論(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是一種用于易于使用的腳本語言,可以用來對(duì)程序進(jìn)行擴(kuò)展及完成一些自動(dòng)化的工作,加上內(nèi)置的一些命令,其功能要比Windows中的DOS的批處理命令功能更強(qiáng)大,使用更方便。Tcl腳本語言是開源免費(fèi)的,可以方便獲取且免費(fèi)使用。

            OpenCASCADE中使用了Tcl/Tk來實(shí)現(xiàn)了一個(gè)自動(dòng)化測(cè)試體系。使用在OpenCASCADE中使用自定義的Tcl命令,可以快速來檢驗(yàn)算法的結(jié)果。通過編寫腳本文件,實(shí)現(xiàn)了測(cè)試的自動(dòng)化。所以學(xué)習(xí)一下Tcl/Tk腳本語言,并在實(shí)際的工作中加以應(yīng)用,可以將一些機(jī)械的勞動(dòng)交給計(jì)算機(jī)自動(dòng)完成。

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

            2. Tcl/Tk Code

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

            #
            # 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

            通過應(yīng)用Tcl/Tk來體驗(yàn)?zāi)_本編程的樂趣,并加深對(duì)Tcl/Tk的理解。從而對(duì)OpenCASCADE的模塊Draw Test Harness更好地理解。

            如果有編程基礎(chǔ),Tcl/Tk會(huì)很快入門的。入門后,可以應(yīng)用其直接編寫一些有意思有腳本,來實(shí)現(xiàn)一些重復(fù)工作的自動(dòng)化。也可將Tcl加入到自己的程序中,增加程序的二次開發(fā)功能。

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


            PDF Version and Script: Iterate Files by Tcl

            日本欧美久久久久免费播放网| 狠狠久久综合伊人不卡| 日产精品久久久久久久性色| 国产一区二区三区久久精品| 91麻精品国产91久久久久| 久久人人爽人人爽人人片AV麻豆 | 久久综合久久性久99毛片| 久久涩综合| 精品久久久久久国产潘金莲| 国产综合免费精品久久久| 亚洲欧美成人综合久久久| 狠狠综合久久综合中文88 | 国产精品熟女福利久久AV| 亚洲国产天堂久久久久久| 91精品国产综合久久精品| 大香伊人久久精品一区二区| 久久99精品国产| 亚洲午夜久久久久久久久电影网| 91久久精品国产成人久久| 久久婷婷五月综合色高清 | 久久久久高潮毛片免费全部播放 | 97r久久精品国产99国产精| 久久亚洲国产精品成人AV秋霞 | 久久强奷乱码老熟女| 99久久国语露脸精品国产| 中文精品99久久国产 | 99re这里只有精品热久久| 漂亮人妻被中出中文字幕久久 | 777午夜精品久久av蜜臀| 久久久人妻精品无码一区| 欧美亚洲另类久久综合| 国产69精品久久久久777| 无码超乳爆乳中文字幕久久| 超级碰碰碰碰97久久久久| 精品人妻伦九区久久AAA片69| 精品久久一区二区三区| 精品久久久无码人妻中文字幕豆芽| 日韩AV毛片精品久久久| 久久婷婷五月综合成人D啪 | jizzjizz国产精品久久| 99久久精品毛片免费播放|