In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Python code modifies the file name in batch:
Import os,sys,remydir=os.path.abspath (sys.argv [1]) os.chdir (mydir) cwd = os.getcwd () # group ID mapid= {"A79_A103_A104_A246_A356_A357_A375_A378_A379_A381_vs_A37_A409_A5_A48_A32_A221_A41_A241_A406_A408": "CW_vs_AW" "A11_A12_A13_A19_A201_A211_A271_A303_A314_A315_A316_A318_A319_A325_A329_A337_A341_A344_A346_A349_A351_A360_A370_vs_A5_A32_A37_A41_A48_A79_A103_A104_A221_A241_A246_A356_A357_A375_A378_A379_A381_A406_A408_A409": "C_vs_W"} i=0for dir_path, dir_names File_names in os.walk (cwd): for file_name in file_names: p=os.path.join (dir_path,file_name) if len (file_name) > 100: m=re.match (r'(. + _ vs_ [^\.] +)' File_name) vs=m.group (1) if (id.has_key (vs)): newfilename=re.sub (r'^ [^\.] + _ vs_ [^\.] +\., "% s."% str (id [vs]), file_name) os.system ("mv% s% s"% (dir_path) Newfilename)) print (os.path.basename (p) + "\ t" + newfilename) else: i=i+1 id [vs] = "DEG%s"% I newfilename=re.sub (r'^ [^\.] + _ vs_ [^\.] +\., "% s."% str (id [vs]) What are the advantages of file_name) os.system ("mv% s"% (precedence os.path.join (dir_path,newfilename) print (os.path.basename (p) + "\ t" + newfilename) Python 1. Easy to use Compared with traditional languages such as Python, Java, C# and so on, Python has less strict requirements on code format. 2. Python is open source, everyone can see the source code, and can be ported to many platforms; 3, Python object-oriented, can support process-oriented programming, but also support object-oriented programming; 4. Python is an interpretive language, programs written by Python do not need to be compiled into binary code, you can run programs directly from the source code 5. Python has powerful functions, has many modules, and can basically achieve all the common functions.
Thank you for reading here. I hope you have the most profound experience on the key issue of "how to modify file names in batches of python" from the practical level, and you need to practice and use it yourself in order to understand it. If you want to read more related articles, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.