删除子目录中的扩展名 [英] removing extensions in subdirectories

查看:318
本文介绍了删除子目录中的扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要删除扩展名.tex:

  ./ 1-aoeeu / 1.tex 
。2/-thst/2.tex
./3-oeu/3.tex
./4-ououeou/4.tex
./5-aaa/5.tex
./6-oeua/6.tex
./7-oue/7.tex

请使用下面的工具:


  1. Sed和find


  2. Ruby

  3. b $ b

    我的穷人尝试:

      $ find。 -maxdepth 2 -name* .tex-ok mv`sed's @ .tex @@ g'{}`{} + 


    解决方案

    一个Python脚本可以做同样的事情:

      import os.path,shutil 
    $ b def remove_ext(arg,dirname,fnames):
    argfiles =(os.path.join(dirname,f)for f in fnames if f.endswith (arg))
    for argfiles:
    shutil.move(f,f [: - len(arg)])

    os.path.walk('/ some / path',remove_ext,'.tex')


    I need to remove the extension ".tex":

    ./1-aoeeu/1.tex
    ./2-thst/2.tex
    ./3-oeu/3.tex
    ./4-uoueou/4.tex
    ./5-aaa/5.tex
    ./6-oeua/6.tex
    ./7-oue/7.tex
    

    Please, do it with some tools below:

    1. Sed and find

    2. Ruby

    3. Python

    My Poor Try:

    $find . -maxdepth 2 -name "*.tex" -ok mv `sed 's@.tex@@g' {}` {} +
    

    解决方案

    A Python script to do the same:

    import os.path, shutil
    
    def remove_ext(arg, dirname, fnames):
        argfiles = (os.path.join(dirname, f) for f in fnames if f.endswith(arg))
        for f in argfiles:
            shutil.move(f, f[:-len(arg)])
    
    os.path.walk('/some/path', remove_ext, '.tex')
    

    这篇关于删除子目录中的扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆