Python Forum
Changing Directory based on user input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Changing Directory based on user input
#10
When you pass the path variable to os.chdir(), you need it to be a valid directory like 'C:\TMP'. When you pass the path variable to glob.glob() (lines 18 and 36), you need it to include a wildcard like 'C:\TMP\*'. My guess is you are passing path without a wildcard in lines 18 and 36, so your glob.glob() loop is not actually finding anything that satisfies the if condition (nothing that ends with .jpg or .png).

import glob

print('Printing items using C:\TMP as path')
for item in glob.glob('C:\TMP'):
    print(item)
    
print('Printing items using C:\TMP\* as path')
for item in glob.glob('C:\TMP\*'):
    print(item)
Output:
Printing items using C:\TMP as path C:\TMP Printing items using C:\TMP\* as path C:\TMP\Testing.jpg C:\TMP\Placeholder.jpg
Reply


Messages In This Thread
RE: Changing Directory based on user input - by GOTO10 - Aug-13-2020, 12:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to create a menu and execute a function based on user selection in python? Thedarkphoenix 1 1,348 Nov-23-2022, 07:53 PM
Last Post: Larz60+
Question Simulate an answer based on user input [Beginner needs guidance] Bombardini 1 1,307 Nov-12-2022, 03:47 AM
Last Post: deanhystad
  Print user input into triangle djtjhokie 1 2,413 Nov-07-2020, 07:01 PM
Last Post: buran
  sys.stdin to do a word count based on user entry Kaltex 3 3,714 Jul-19-2020, 01:54 PM
Last Post: deanhystad
  how to add the user input from file into list wilson20 8 4,356 May-03-2020, 10:52 PM
Last Post: Larz60+
  Writing a function that changes its answer based on user input SirRavenclaw 2 2,841 Dec-21-2019, 09:46 PM
Last Post: Clunk_Head
  Print the longest str from user input edwdas 5 4,193 Nov-04-2019, 02:02 PM
Last Post: perfringo
  how to add user input to a dictionary to a graph KINGLEBRON 3 3,070 Jul-31-2019, 09:09 PM
Last Post: SheeppOSU
  New to Python - tiny coding assistance on user input function and assign to variable Mountain_Duck 1 2,535 Mar-23-2019, 06:54 PM
Last Post: Yoriz
  Extracting list element with user input valve 1 2,598 Mar-11-2019, 07:37 PM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020