From: blur959 on
Hi, all, I am writing a program that renames files inside OS
directories the user provides. I am at the early stage of writing it
and I encountered some problems.

Below is my code. There is an error i received when i run this code.
The error is, WindowsError: [Error 123] The filename, directory name,
or volume label syntax is incorrect.

Hope you guys could help.



import os, glob

def fileDirectory():
#Asks the user for a file root directory
fileroot = raw_input("Please input the file root directory \n\n")
print fileroot

#Returns a list with all the files inside the file root directory
os.listdir(fileroot)

fileDirectory()
From: Chris Rebert on
On Sun, Aug 8, 2010 at 1:02 AM, blur959 <blur959(a)hotmail.com> wrote:
> Hi, all, I am writing a program that renames files inside OS
> directories the user provides. I am at the early stage of writing it
> and I encountered some problems.
>
> Below is my code. There is an error i received when i run this code.
> The error is, WindowsError: [Error 123] The filename, directory name,
> or volume label syntax is incorrect.

Well, what directory did you input? Apparently it wasn't a valid or extant one.

Cheers,
Chris
--
http://blog.rebertia.com
From: blur959 on
On Aug 8, 4:15 pm, Chris Rebert <c...(a)rebertia.com> wrote:
> On Sun, Aug 8, 2010 at 1:02 AM, blur959 <blur...(a)hotmail.com> wrote:
> > Hi, all, I am writing a program that renames files inside OS
> > directories the user provides. I am at the early stage of writing it
> > and I encountered some problems.
>
> > Below is my code. There is an error i received when i run this code.
> > The error is, WindowsError: [Error 123] The filename, directory name,
> > or volume label syntax is incorrect.
>
> Well, what directory did you input? Apparently it wasn't a valid or extant one.
>
> Cheers,
> Chris
> --http://blog.rebertia.com


I input for e.g, "C:" it works, basically, if i input a hard code
string inside os.listdir it works, but if i stored the string that the
user keyed inside a variable and run os.listdir with the variable,
there is that error. But inputing hard code string inside os.listdir
isn't what I want when I am writing this program.
From: Thomas Jollans on
On 08/08/2010 10:35 AM, blur959 wrote:
> On Aug 8, 4:15 pm, Chris Rebert <c...(a)rebertia.com> wrote:
>> On Sun, Aug 8, 2010 at 1:02 AM, blur959 <blur...(a)hotmail.com> wrote:
>>> Hi, all, I am writing a program that renames files inside OS
>>> directories the user provides. I am at the early stage of writing it
>>> and I encountered some problems.
>>
>>> Below is my code. There is an error i received when i run this code.
>>> The error is, WindowsError: [Error 123] The filename, directory name,
>>> or volume label syntax is incorrect.
>>
>> Well, what directory did you input? Apparently it wasn't a valid or extant one.
>>
>> Cheers,
>> Chris
>> --http://blog.rebertia.com
>
>
> I input for e.g, "C:" it works, basically, if i input a hard code
> string inside os.listdir it works, but if i stored the string that the
> user keyed inside a variable and run os.listdir with the variable,
> there is that error. But inputing hard code string inside os.listdir
> isn't what I want when I am writing this program.

You didn't answert the question. What is the actual string you pass to
os.listdir after you got it from the user? You could
print repr(fileroot)
to find out.

My tentative guess is that maybe Windows doesn't like newlines in file
names (I know UNIX allows them, but they're still usually a bad idea)
and maybe you string ends with a newline.
From: blur959 on
On Aug 8, 6:05 pm, Thomas Jollans <tho...(a)jollans.com> wrote:
> On 08/08/2010 10:35 AM, blur959 wrote:
>
>
>
> > On Aug 8, 4:15 pm, Chris Rebert <c...(a)rebertia.com> wrote:
> >> On Sun, Aug 8, 2010 at 1:02 AM, blur959 <blur...(a)hotmail.com> wrote:
> >>> Hi, all, I am writing a program that renames files inside OS
> >>> directories the user provides. I am at the early stage of writing it
> >>> and I encountered some problems.
>
> >>> Below is my code. There is an error i received when i run this code.
> >>> The error is, WindowsError: [Error 123] The filename, directory name,
> >>> or volume label syntax is incorrect.
>
> >> Well, what directory did you input? Apparently it wasn't a valid or extant one.
>
> >> Cheers,
> >> Chris
> >> --http://blog.rebertia.com
>
> > I input for e.g, "C:" it works, basically, if i input a hard code
> > string inside os.listdir it works, but if i stored the string that the
> > user keyed inside a variable and run os.listdir with the variable,
> > there is that error. But inputing hard code string inside os.listdir
> > isn't what I want when I am writing this program.
>
> You didn't answert the question. What is the actual string you pass to
> os.listdir after you got it from the user? You could
>     print repr(fileroot)
> to find out.
>
> My tentative guess is that maybe Windows doesn't like newlines in file
> names (I know UNIX allows them, but they're still usually a bad idea)
> and maybe you string ends with a newline.



I do not get what you mean. The string i passed in is stored inside
the variable fileroot. In the case I tested, i inputed the string "C:
\" inside the raw_input and stored it inside fileroot, I tried
printing repr(fileroot) and it gave me "C:\" as the result and when i
tried running os.listdir(fileroot) i got the error. The string i
passed to os.listdir is the string i keyed inside fileroot under the
raw_input?