I have a set of text files in a folder. I want to read each file, convert the contents of the file to lowercase, remove punctuations and save them all in another directory with the same filenames. How can i do that???

Recommended Answers

All 2 Replies

Show us some code.

file1 = open(filname) # Opens a file to read
words_in_file = file1.read() # Reads everything in the file

Here's another bit of code that will give you part of the solution:

import os
dirpath = '/the/directory/path' # or maybe r'D:\the\directory\path'
for item in os.listdir(dirpath):
  p = os.path.join(dirpath,item)
  desc = 'file'
  if os.path.isdir(p):
    desc = 'folder'
  if os.path.islink(p):
    desc += ' (link)'
  print("I found a %s: %s"%(desc,p))

http://docs.python.org/library/os.html#os.listdir and http://docs.python.org/library/os.path.html#os.path.join

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.