Python file operation exercise: Print all the filenames in a directory, do not include the suffix name

Source: Internet
Author: User

#coding =utf-8

Import OS
Os.chdir (' D:\\test2 ')
File_list=os.listdir ('. ')
Print "File_list:", file_list
Print "*" *100

For file in File_list:
Print Os.path.splitext (file) [0]

C:\python27\scripts>python task_test.py
File_list: [' 3rdParty access-requestform_team-apac-v2 edited by Tc.docx ', ' Carton status.xlsx ', ' Copy of IT Shifts o n Feb and Mar. 2.27-3.18.xlsx ', ' DB connection ', ' EXPORT ', ' export.xlsx ', ' export0131.xlsx ', ' Handle data format for SQL.D OCX ', ' handover ', ' Issue archivement.pst ', ' New Microsoft Excel worksheet.xlsx ', ' pkt status.xlsx ', ' Short_health Check gu Ide.docx ', ' Support note.xlsx ', ' Support note_bkp.xlsx ', ' Support summary.docx ', ' ~ $actice. docx ', ' ~ $ort _health Check Guide.docx ', ' ~ $pport summary.docx ', ' ~ $Support note.xlsx ', ' ~wrl0003.tmp ', ' ~wrl1399.tmp ', '?? Microsoft Office Word Document.docx ']
****************************************************************************************************
3rdParty Access-requestform_team-apac-v2 edited by TC
Carton status
Copy of IT Shifts on Feb and Mar. 2.27-3.18
DB Connection
EXPORT
Export
export0131
Handle data format for SQL
Handover
Issue archivement
New Microsoft Excel Worksheet
PKT Status
Short_health Check Guide
Support Note
Support NOTE_BKP
Support Summary
~ $actice
~ $ort _health Check Guide
~ $pport Summary
~ $Support Note
~wrl0003
~wrl1399
?? Microsoft Office Word Document

Python file operation exercise: Print all the filenames in a directory, do not include the suffix name

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.