0
import os

def rename_files():
    file_list = os.listdir(r"C:\Users\jsun0011\Downloads\prank")
    print(file_list)

As I run the code, the output is supposed to display the files of the folder named "prank", yet nothings showing up. (in the pic) enter image description here

Thomas Smyth
  • 3,953
  • 5
  • 22
  • 33
Monday
  • 1
  • 2
  • 1
    "pic"? Did you forget to post a picture? – cs95 Dec 30 '17 at 09:32
  • 3
    did you call `rename_files`? At least, empty list `[]` should be printed. – Daniel Dec 30 '17 at 09:32
  • I cannot write an answer as I cannot test any code right now, but please check that S.O. link https://stackoverflow.com/questions/89228/calling-an-external-command-in-python as i think os returns an execution return code (success or fail), not a return value as subprocess.call does. – Vulpo Dec 30 '17 at 11:41

1 Answers1

2

Your code seems to be fine and if you're not getting anything as output, there may be 2 cases:

  1. prank folder doesn't contain anything, even in this case - It should've given empty list i.e.[]

  2. you're not calling rename_files method anywhere (probably, this is your case), Kindly make a function call as defined below:

import os

def rename_files():
    file_list = os.listdir(r"C:\Users\jsun0011\Downloads\prank")
    print(file_list)

rename_files()
Community
  • 1
  • 1
Talat Parwez
  • 113
  • 4