0

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

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by griswolf
0

Show us some code.

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

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

Edited by griswolf: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.