How to open a remote file using python.
Hello all, I am writing an application where I need to open a shared file on a remote machine using python script. I tried using the following function: f = urllib.open("\\remote_machine\\folder1\\file1.doc") I also tried using class urllib.FancyURLopener(...) but didn't work. Can some one help me in this regard. Thank you in advance, Venu -- http://mail.python.org/mailman/listinfo/python-list
Re: How to open a remote file using python.
On Feb 23, 9:25 am, MRAB wrote: > venutaurus...@gmail.com wrote: > > Hello all, > > I am writing an application where I need to open a shared > > file on a remote machine using python script. I tried using the > > following function: > > > f = urllib.open("\\remote_machine\\folder1\\file1.doc") > > > I also tried using > > > class urllib.FancyURLopener(...) > > > but didn't work. Can some one help me in this regard. > > What do you mean by "remote machine"? Do you mean you want to open a > file that's in a shared folder on a machine that's on the same local > network? > > If it's meant to be a Windows filepath then it should be: > > f = open(r"\\remote_machine\folder1\file1.doc") > > (If the file is a Microsoft Word document file, then you won't probably > be able to make much sense of its contents using open().) Thanks to all for your brisk replies: Yes, my aim is to open a file from another machine in the same LAN. It also worked using >>f = urllib.urlopen("\\\remote_machine\\folder\\file.doc") But now I also have to copy the same file to the local machine in Python. Do I need to follow any protocols for this? Thank you, Venu. -- http://mail.python.org/mailman/listinfo/python-list
opening files with names in non-english characters.
Hi all, I am trying to find the attributes of afile whose name has non english characters one like given below. When I try to run my python scirpt, it fails giving out an error filename must be in string or UNICODE. When i try to copy the name of the file as a strinig, it (KOMODO IDE) is not allowing me to save the script saying that it cannot convert some of the characters in the current encoding which is Western European(CP-1252). 0010testUnicode_ėíîïðņōóôõöũøųúûüýþĸ !#$%&'()+,-. 0123456789;=...@abcd.txt.txt Hope some one could help me in this regard. Thank you in advance, Venu Madhav -- http://mail.python.org/mailman/listinfo/python-list
Re: opening files with names in non-english characters.
On Feb 23, 11:02 pm, Chris Rebert wrote: > On Mon, Feb 23, 2009 at 5:51 AM, venutaurus...@gmail.com > > wrote: > > Hi all, > > I am trying to find the attributes of afile whose name has > > non english characters one like given below. When I try to run my > > python scirpt, it fails giving out an error filename must be in string > > or UNICODE. When i try to copy the name of the file as a strinig, it > > (KOMODO IDE) is not allowing me to save the script saying that it > > cannot convert some of the characters in the current encoding which is > > Western European(CP-1252). > > > 0010testUnicode_ėíîïðņōóôõöũøųúûüýþĸ !#$%&'()+,-. > > 0123456789;=...@abcd.txt.txt > > (1) How are you entering or retrieving that filename? > (2) Please provide the exact error and Traceback you're getting. > > Cheers, > Chris > > -- > Follow the path of the Iguana...http://rebertia.com Hello, First of all thanks for your response. I've written a function as shown below to recurse a directory and return a file based on the value of n. I am calling this fucntion from my main code to catch that filename. The folder which it recurses through contains a folder having files with unicode names (as an example i've given earlier. - def findFile(dir_path): for name in os.listdir(dir_path): full_path = os.path.join(dir_path, name) print full_path if os.path.isdir(full_path): findFile(full_path) else: n = n - 1 if(n ==0): return full_path -- The problem is in the return statement. In the function when I tried to print the file name, it is printing properly but the receiving variable is not getting populated with the file name. The below code (1st statement) shows the value of the full_path variable while the control is at the return statement. The second statement is in the main code from where the function call has been made. Once the control has reached the main procedure after executing the findFile procedure, the third statement gives the status of file variable which has type as NoneType and value as None. Now when I try to check if the path exists, it fails giving the below trace back. -- E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder \0003testUnicode_ÍÎIÐNOKÔÕÖרUÚÛÜUUßaáâãäåæicéeëeíîidnokôõö÷øuúûüuu.txt.txt file = findFile(fpath) --- file NoneType None --- This is the final trace back: Traceback (most recent call last): File "C:\RecallStubFopen.py", line 268, in if os.path.exists(file): File "C:\Python26\lib\genericpath.py", line 18, in exists st = os.stat(path) TypeError: coercing to Unicode: need string or buffer, NoneType found --- Please ask if you need any further information. Thank you, Venu -- http://mail.python.org/mailman/listinfo/python-list
Re: opening files with names in non-english characters.
On Feb 24, 8:29 am, "venutaurus...@gmail.com" wrote: > On Feb 23, 11:02 pm, Chris Rebert wrote: > > > > > On Mon, Feb 23, 2009 at 5:51 AM, venutaurus...@gmail.com > > > wrote: > > > Hi all, > > > I am trying to find the attributes of afile whose name has > > > non english characters one like given below. When I try to run my > > > python scirpt, it fails giving out an error filename must be in string > > > or UNICODE. When i try to copy the name of the file as a strinig, it > > > (KOMODO IDE) is not allowing me to save the script saying that it > > > cannot convert some of the characters in the current encoding which is > > > Western European(CP-1252). > > > > 0010testUnicode_ėíîïðņōóôõöũøųúûüýþĸ !#$%&'()+,-. > > > 0123456789;=...@abcd.txt.txt > > > (1) How are you entering or retrieving that filename? > > (2) Please provide the exact error and Traceback you're getting. > > > Cheers, > > Chris > > > -- > > Follow the path of the Iguana...http://rebertia.com > > Hello, > First of all thanks for your response. I've written a function > as shown below to recurse a directory and return a file based on the > value of n. I am calling this fucntion from my main code to catch that > filename. The folder which it recurses through contains a folder > having files with unicode names (as an example i've given earlier. > --- -- > def findFile(dir_path): > for name in os.listdir(dir_path): > full_path = os.path.join(dir_path, name) > print full_path > if os.path.isdir(full_path): > findFile(full_path) > else: > n = n - 1 > if(n ==0): > return full_path > --- > --- > The problem is in the return statement. In the > function when I tried to print the file name, it is printing properly > but the receiving variable is not getting populated with the file > name. The below code (1st statement) shows the value of the full_path > variable while the control is at the return statement. The second > statement is in the main code from where the function call has been > made. > Once the control has reached the main procedure after executing the > findFile procedure, the third statement gives the status of file > variable which has type as NoneType and value as None. Now when I try > to check if the path exists, it fails giving the below trace back. > > --- > --- > > E:\DataSet\Unicode\UnicodeFiles_8859\001_0006_test_folder > \0003testUnicode_ÍÎIÐNOKÔÕÖרUÚÛÜUUßaáâãäåæicéeëeíîidnokôõö÷øuúûüuu.txt.txt > --- > --- > -- > file = findFile(fpath) > --- > --- > - > file > NoneType > None > > --- > --- > - > This is the final trace back: > > Traceback (most recent call last): > File "C:\RecallStubFopen.py", line 268, in > if os.path.exists(file): > File "C:\Python26\lib\genericpath.py", line 18, in exists > st = os.stat(path) > TypeError: coercing to Unicode: need string or buffer, NoneType found > > --- > --- > - > > Please ask if you need any further information. > > Thank you, > Venu To add to what I've said above...I tried manual conversion of the file using unicode() function which is throwing this error: Traceback (most recent call last): File "C:\RecallStubFopen.py", line 278, in file = unicode(file) UnicodeDecodeError: 'ascii' codec can't decode byte 0xeb in position 74: ordinal not in range(128) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem in accessing files with unicode fonts.
On Feb 24, 1:44 pm, "Gabriel Genellina" wrote: > En Tue, 24 Feb 2009 05:15:33 -0200, venu madhav > escribió: > > > > >> > def findFile(dir_path): > >> > for name in os.listdir(dir_path): > >> > full_path = os.path.join(dir_path, name) > >> > print full_path > >> > if os.path.isdir(full_path): > >> > findFile(full_path) > >> > else: > >> > v = unicode(full_path,errors='skip') > >> > i = win32api.GetFileAttributes(v) > > >> > findFile("F:\\DataSet\\Unicode") > >> > --- > >> > Now when I run this scirpt, the full_path variable which should > >> contain > >> the > >> > name of the file has "" for non english ( I tried Arabic) > >> characters. > >> As > >> > a result the getfileattributes function is failing to recognise that > >> file > >> > and is raising an exception. > >> > i = win32api.GetFileAttributes(v) > >> > error: (123, 'GetFileAttributes', 'The filename, directory name, or > >> volume > >> > label syntax is incorrect.') > > If you call os.listdir with an unicode directory, it returns unicode file > names. > That is (after correcting the previous error in findFile), call it using: > findFile(u"F:\\DataSet\\Unicode") > > -- > Gabriel Genellina Thank you for your solution. It really helped. But how should I give if my path is in a varialble. For ex: path has that value obtained through command line arguments. path = sys.argv[2] In such a case how can we convert the path to UNICODE? Thank you once again, Venu -- http://mail.python.org/mailman/listinfo/python-list
Problem with os.system()
Hello, I am facing problems while using os.system() of python for copying a file from source to destination where the file name is in unicode (multi lingual characters).My python interpreter is trying to convert them to ascii and is failing. I tried giving unicode string as input for the function something like: c = u"copy "+"\""+full_path+"\" "+dest os.system (c) where the full_path contains filenames with unicode characters(unicode data type). I tried searching in google and came to know that UNICODE support wasn't there for os.system function till python2.3[1]. Currently I am using python2.6 but couldn't find anywhere whether a support has been provided or not. Can some one suggest me any work around for this. If I do a manual encoding of the file name to ascii, it results in loss of data and hence the copy command wouldn't find the file name. - Traceback (most recent call last): File "C:\unitest.py", line 32, in findFile(u"E:\\New Folder") File "C:\unitest.py", line 17, in findFile findFile(full_path) File "C:\unitest.py", line 17, in findFile findFile(full_path) File "C:\unitest.py", line 27, in findFile os.system (c) UnicodeEncodeError: 'ascii' codec can't encode characters in position 47-72: ordinal not in range(128) -- [1] http://mail.python.org/pipermail/python-list/2003-January/182182.html Thanks in advance, Venu M -- http://mail.python.org/mailman/listinfo/python-list
Problem with os.system()
Hello, I am facing problems while using os.system() of python for copying a file from source to destination where the file name is in unicode (multi lingual characters).My python interpreter is trying to convert them to ascii and is failing. I tried giving unicode string as input for the function something like: c = u"copy "+"\""+full_path+"\" "+dest os.system (c) where the full_path contains filenames with unicode characters(unicode data type). I tried searching in google and came to know that UNICODE support wasn't there for os.system function till python2.3[1]. Currently I am using python2.6 but couldn't find anywhere whether a support has been provided or not. Can some one suggest me any work around for this. If I do a manual encoding of the file name to ascii, it results in loss of data and hence the copy command wouldn't find the file name. - Traceback (most recent call last): File "C:\unitest.py", line 32, in findFile(u"E:\\New Folder") File "C:\unitest.py", line 17, in findFile findFile(full_path) File "C:\unitest.py", line 17, in findFile findFile(full_path) File "C:\unitest.py", line 27, in findFile os.system (c) UnicodeEncodeError: 'ascii' codec can't encode characters in position 47-72: ordinal not in range(128) -- [1] http://mail.python.org/pipermail/python-list/2003-January/182182.html Thanks in advance, Venu M -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with os.system()
On Feb 25, 9:55 am, Christian Heimes wrote: > venutaurus...@gmail.com schrieb: > > > Hello, > > I am facing problems while using os.system() of python for > > copying a file from source to destination where the file name is in > > unicode (multi lingual characters).My python interpreter is trying to > > convert them to ascii and is failing. I tried giving unicode string as > > input for the function something like: > > > c = u"copy "+"\""+full_path+"\" "+dest > > os.system (c) > > First of all do not use os.system() to run external programs. You'll get > in all sorts of trouble like quoting. You are far better of with the > subprocess module. > > Second, why are you using an external program at all? The shutil module > contains multiple functions to copy a file or directory. > > import shutil > shutil.copy(source, dest) > > Christian Thanks Christian for your reply,will definitely try. -- http://mail.python.org/mailman/listinfo/python-list
Finding the attributes of a file
Hello all, I am writing an application which has to identify the archived files in a given directory.I've tried using the function i = win32api.GetFileAttributes (full_path) to obtain the attributes.But am unable to identify based on the value it returns as it is returning 5152, 13856 etc for different files but all of them are archived. Is there any way to come to a conclusion using these numbers about whether a file is archived or not. Thanks in advance, Venu -- http://mail.python.org/mailman/listinfo/python-list
Run a python script as an exe and run a new process from it
Hello all, I've a strange requirement where I need to run a python script just as we run an exe (by double clicking through windows explorer or by typing the script name at command prompt). In that process I should be able to execute another python script in such a way that, the second script should continue running but the main one should terminate without effecting the second one. My requirement may be little confusing so please get back if you didn't understand what I meant above. Thank you, Venu. -- http://mail.python.org/mailman/listinfo/python-list
Re: Run a python script as an exe and run a new process from it
On Feb 26, 6:10 pm, Tim Wintle wrote: > On Thu, 2009-02-26 at 04:55 -0800, venutaurus...@gmail.com wrote: > > Hello all, > > I've a strange requirement where I need to run a python > > script just as we run an exe (by double clicking through windows > > explorer or by typing the script name at command prompt). > > I don't know how windows deals with this part> In that > > process I should be able to execute another python script in such a > > way that, the second script should continue running but the main one > > should terminate without effecting the second one. > > standard daemon behavior I'd have thought > > This shows how you would do it (with lots of comments). Assume this > should work on Windows. > > http://code.activestate.com/recipes/278731/ > > note the two child threads to prevent zombies - may not be needed on > windows but good to use them anyway. Thanks for the reply, Being a newbie to python, I am finding it difficult to understand the logic even after thorough reading of comments. Is there any simpler way where I can just run a python script from the main script and exit without disturbing the second one(This will end based on some other constraints which can be handled). Or can some one throw some light on where should I run the function os.system(" python script2.py") from the main one. Thank you, venu -- http://mail.python.org/mailman/listinfo/python-list
Re: Run a python script as an exe and run a new process from it
On Feb 26, 7:00 pm, "venutaurus...@gmail.com" wrote: > On Feb 26, 6:10 pm, Tim Wintle wrote: > > > > > On Thu, 2009-02-26 at 04:55 -0800, venutaurus...@gmail.com wrote: > > > Hello all, > > > I've a strange requirement where I need to run a python > > > script just as we run an exe (by double clicking through windows > > > explorer or by typing the script name at command prompt). > > > I don't know how windows deals with this part> In that > > > process I should be able to execute another python script in such a > > > way that, the second script should continue running but the main one > > > should terminate without effecting the second one. > > > standard daemon behavior I'd have thought > > > This shows how you would do it (with lots of comments). Assume this > > should work on Windows. > > >http://code.activestate.com/recipes/278731/ > > > note the two child threads to prevent zombies - may not be needed on > > windows but good to use them anyway. > > Thanks for the reply, > Being a newbie to python, I am finding it difficult to > understand the logic even after thorough reading of comments. Is there > any simpler way where I can just run a python script from the main > script and exit without disturbing the second one(This will end based > on some other constraints which can be handled). Or can some one throw > some light on where should I run the function os.system(" python > script2.py") from the main one. > > Thank you, > venu Adding to the above.. I've to do it in Windows platform and what I can see from the illustration (/dev/null) etc. they are for Unix Environment. Thank you, Venu -- http://mail.python.org/mailman/listinfo/python-list
Re: Run a python script as an exe and run a new process from it
On Feb 26, 7:47 pm, Tim Wintle wrote: > On Thu, 2009-02-26 at 06:00 -0800, venutaurus...@gmail.com wrote: > > Thanks for the reply, > > Being a newbie to python, I am finding it difficult to > > understand the logic even after thorough reading of comments. Is there > > any simpler way where I can just run a python script from the main > > script and exit without disturbing the second one(This will end based > > on some other constraints which can be handled). Or can some one throw > > some light on where should I run the function os.system(" python > > script2.py") from the main one. > > That would be a simple way of doing it :-) When I run that script on Windows it fails throwing the below error: AttributeError: 'module' object has no attribute 'fork' Please help me out.. -- http://mail.python.org/mailman/listinfo/python-list
Re: Run a python script as an exe and run a new process from it
On Feb 26, 11:14 pm, "Paddy O'Loughlin" wrote: > Try this as an outline: > script1.py > from subprocess import Popen > > if __name__ == '__main__': > scriptname = "script2.py" > > Popen("python %s" % scriptname, shell=True) > > print "I'm done" > > script2.py > from time import sleep > > if __name__ == '__main__': > while (True): > print "waiting.." > sleep(2) > > ### > If you install python using the Windows Installer (.exe), it should > set up .py files to be opened by python when double-clicking on them. > Alternatively, you can right-click on your .py file and go to "Open > With..." then "choose program", then click "Browse...", you can Browse > to the python executable, so Explorer will use it to open .py files > when you double-click on them. > > As someone else mentioned there is also a py2exe program. Google it. > > 2009/2/26 venutaurus...@gmail.com : > > > > > Hello all, > > I've a strange requirement where I need to run a python > > script just as we run an exe (by double clicking through windows > > explorer or by typing the script name at command prompt). In that > > process I should be able to execute another python script in such a > > way that, the second script should continue running but the main one > > should terminate without effecting the second one. > > > My requirement may be little confusing so please > > get back if you didn't understand what I meant above. > > > Thank you, > > Venu. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > -- > "Ray, when someone asks you if you're a god, you say YES!" Thanks for the reply,, I am trying to use the above application using psexec()in command line.But it failed returning the error message exited with error code 255. But when I ran the application normally it worked fine.Do I need to add anything to my python script(either the main one or the script which is calling it) to make it work. Thank you, Venu Madhav. -- http://mail.python.org/mailman/listinfo/python-list
Problem with py2exe conversion.
Hello all, I am facing an interesting problem with py2exe conversion. I've a python script which uses the shutil libarary. When I convert that python script into exe, it creates a dist folder and then in that it places the exe. Along with the exe it also places a zip folder containing pre compiled python scripts( library.zip).I have two Win2003 machines.On one machine when I genreate the exe that zip file also contains this shutil.pyc, but when I build the same python script on the second machine, that shutli.pyc is missing in that zip file as a result fo which I am unable to use that library on the second machine. When I use it, it throws an error: ImportError: No module named shutil Can some one please suggest me a solution for this. Thanks in advance, Venu -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with py2exe conversion.
On Mar 4, 6:23 pm, "Gabriel Genellina" wrote: > En Wed, 04 Mar 2009 11:12:32 -0200, venutaurus...@gmail.com > escribió: > > > Hello all, > > I am facing an interesting problem with py2exe conversion. > > I've a python script which uses the shutil libarary. When I convert > > that python script into exe, it creates a dist folder and then in that > > it places the exe. Along with the exe it also places a zip folder > > containing pre compiled python scripts( library.zip).I have two > > Win2003 machines.On one machine when I genreate the exe that zip file > > also contains this shutil.pyc, but when I build the same python script > > on the second machine, that shutli.pyc is missing in that zip file as > > a result fo which I am unable to use that library on the second > > machine. When I use it, it throws an error: > > > ImportError: No module named shutil > > > Can some one please suggest me a solution for this. > > Are you sure it's the same script? The same setup.py? The same py2exe > version? Aren't you sharing the same directory for several projects? > > -- > Gabriel Genellina Thanks for the reply.. 1. It is the same script. Moreover even if the scripts change, if my script uses that module, shouldn't it be there in that zip. 2. I've used the same installer on the second machine too. 3. No, am not sharing the directory. Another observation I made is, if I copy the library.zip file from the first machine to the second machine, these script runs without any exception. But I can't every time copy the zip.:-( Thank you once again, Venu Madhav. -- http://mail.python.org/mailman/listinfo/python-list
Problem in accessing long paths.
Hello All, I have a requirement where I've to access folders with path lengths >255 ( Windows only supports 255). To do this I've created junction points for the folders whose length is > 255. The problem is my python script is unable to recognize these junction points. As an example I've a junction point JC04 pointing to a folder DeepPathLevel57which has path length around 700. When I do "cd E:\JunctionPaths\JC04\DeepPathLevel57" at command prompt, am able to access the folder. When I try to list the directories in that folder using os.listdir in python am getting the below error. --- Traceback (most recent call last): File "C:\JPDump\RecallStubFopen.py", line 362, in for f in os.listdir(fpath): WindowsError: [Error 3] The system cannot find the path specified: u'E: \\JunctionPaths\\JC04\\DeepPathLevel57\\*.*' -- Can some one please help me in this. Thank you, Venu Madhav. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem in accessing long paths.
On Mar 6, 7:09 pm, "Tim Golden" wrote: > venutaurus...@gmail.com wrote: > > Hello All, > > I have a requirement where I've to access folders with > > path lengths >255 ( Windows only supports 255). To do this I've > > created junction points for the folders whose length is > 255. The > > problem is my python script is unable to recognize these junction > points. > > > As an example I've a junction point JC04 pointing to a folder > > DeepPathLevel57which has path length around 700. When I do > > > "cd E:\JunctionPaths\JC04\DeepPathLevel57" at command prompt, am able to > > access the folder. When I try to list the directories in that folder > using os.listdir in python am getting the below error. > > You shouldn't need to mess around with junction points; > just recast your r"c:\very\long\...\path" as > ur"\\?\c:\very\long\...path" and pass that into whatever > function you're using. > > More info here: > > http://msdn.microsoft.com/en-us/library/aa365247(VS.85).aspx > > TJG Thank you very much for your reply... but will the same work if I try to open it like the below? f = open("\\?\C:\very\very\...path") Thank you, Venu Madhav. -- http://mail.python.org/mailman/listinfo/python-list
Problem with os.chdir()
Hello all, I am writing a python script which has to access deep paths then supported normally by the Windows OS (>255). So I am appending "\ \?\" to do so. But when I use the path in the above fashion with os.chdir() it is unable to recognize my folder and throwing an error: Traceback (most recent call last): File "C:\JPDump\test.py", line 31, in renameStubs(file) File "C:\JPDump\test.py", line 15, in renameStubs os.chdir (path) WindowsError: [Error 123] The filename, directory name, or volume label syntax is incorrect: '\\?\\C:\\TestDataSet\ \Many_Files_1_1KB_FIles\\001_0009_1000 FILES\\' The value of my path variable is \?\C:\TestDataSet\Many_Files_1_1KB_FIles\001_0009_1000 FILES\ Can someone please help me in this.. Thank you, Venu M -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with os.chdir()
On Mar 11, 11:08 am, Tim Golden wrote: > venutaurus...@gmail.com wrote: > > Hello all, > > I am writing a python script which has to access deep paths > > then supported normally by the Windows OS (>255). So I am appending "\ > > \?\" to do so. But when I use the path in the above fashion with > > os.chdir() it is unable to recognize my folder and throwing an error: > > > Traceback (most recent call last): > > File "C:\JPDump\test.py", line 31, in > > renameStubs(file) > > File "C:\JPDump\test.py", line 15, in renameStubs > > os.chdir (path) > > WindowsError: [Error 123] The filename, directory name, or volume > > label syntax is incorrect: '\\?\\C:\\TestDataSet\ > > \Many_Files_1_1KB_FIles\\001_0009_1000 FILES\\' > > > The value of my path variable is > > \?\C:\TestDataSet\Many_Files_1_1KB_FIles\001_0009_1000 FILES\ > > There need to be two backslashes at the beginning: > > \\?\C:\TEST.FILES\ > > Note the double backslash before the question mark. > > TJG I've another situation where os.chdir() function failed. Please find the traceback pasted below: Traceback (most recent call last): File "C:\JPDump\test.py", line 29, in renameStubs(file) File "C:\JPDump\test.py", line 12, in renameStubs os.chdir (path) WindowsError: [Error 206] The filename or extension is too long: '\\?\ \C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\ \DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\ \DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\ \DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\ \DeepPathLevel15\\DeepPathLevel16\\' Thanks in advance, Venu Madhav. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with os.chdir()
On Mar 11, 5:02 pm, Tim Golden wrote: > venutaurus...@gmail.com wrote: > > On Mar 11, 11:08 am, Tim Golden wrote: > >> venutaurus...@gmail.com wrote: > >>> Hello all, > >>> I am writing a python script which has to access deep paths > >>> then supported normally by the Windows OS (>255). So I am appending "\ > >>> \?\" to do so. But when I use the path in the above fashion with > >>> os.chdir() it is unable to recognize my folder and throwing an error: > >>> Traceback (most recent call last): > >>> File "C:\JPDump\test.py", line 31, in > >>> renameStubs(file) > >>> File "C:\JPDump\test.py", line 15, in renameStubs > >>> os.chdir (path) > >>> WindowsError: [Error 123] The filename, directory name, or volume > >>> label syntax is incorrect: '\\?\\C:\\TestDataSet\ > >>> \Many_Files_1_1KB_FIles\\001_0009_1000 FILES\\' > >>> The value of my path variable is > >>> \?\C:\TestDataSet\Many_Files_1_1KB_FIles\001_0009_1000 FILES\ > >> There need to be two backslashes at the beginning: > > >> \\?\C:\TEST.FILES\ > > >> Note the double backslash before the question mark. > > >> TJG > > > I've another situation where os.chdir() function failed. Please find > > the traceback pasted below: > > Traceback (most recent call last): > > File "C:\JPDump\test.py", line 29, in > > renameStubs(file) > > File "C:\JPDump\test.py", line 12, in renameStubs > > os.chdir (path) > > WindowsError: [Error 206] The filename or extension is too long: '\\?\ > > \C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\ > > \DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\ > > \DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\ > > \DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\ > > \DeepPathLevel15\\DeepPathLevel16\\' > > Try it as a unicode string: > > os.chdir (ur"\\?\c:\test...\deep...") > > TJG Sorry.. even that failed: Traceback (most recent call last): File "C:\JPDump\test.py", line 29, in renameStubs(file) File "C:\JPDump\test.py", line 12, in renameStubs os.chdir (path) WindowsError: [Error 206] The filename or extension is too long: u'\\\ \?\\C:TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\ \DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\ \DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\ \DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\ \DeepPathLevel15\\DeepPathLevel16\\' --- Here is my code snippet which you will be interested in: file = ur'\\?\C:\\TestDataSet\DeepPaths \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLevel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepPathLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt' def renameStubs(file): #e.write(u"\n"+strftime("%Y-%m-%d %H:%M:%S") +" we are in renameStubs function \n") drive = file.split(":")[0] oldName = file.split("\\")[-1] path = file.rstrip(oldName) os.chdir (path) renameStubs(file) -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with os.chdir()
On Mar 11, 5:19 pm, Tim Golden wrote: > > Here is my code snippet which you will be interested in: > > Indeed. > > > file = ur'\\?\C:\\TestDataSet\DeepPaths > > \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe > > vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP > > athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ > > DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt' > > And what happens if you remove that second double-backslash, > the one between C: and TestDataSet? > > TJG Even if I give the file path as below file = ur'\\?\C:\TestDataSet\DeepPaths \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLevel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepPathLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt' I am still getting the exception: Traceback (most recent call last): File "C:\JPDump\test.py", line 29, in renameStubs(file) File "C:\JPDump\test.py", line 12, in renameStubs os.chdir (path) WindowsError: [Error 206] The filename or extension is too long: u'\\\ \?\\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\ \DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\ \DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\ \DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\ \DeepPathLevel15\\DeepPathLevel16\\' Please help.. Thank you, Venu M -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with os.chdir()
On Mar 11, 6:41 pm, Tim Golden wrote: > venutaurus...@gmail.com wrote: > > On Mar 11, 5:19 pm, Tim Golden wrote: > >>> Here is my code snippet which you will be interested in: > >> Indeed. > > >>> file = ur'\\?\C:\\TestDataSet\DeepPaths > >>> \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe > >>> > >>> vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP > >>> > >>> athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ > >>> DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt' > >> And what happens if you remove that second double-backslash, > >> the one between C: and TestDataSet? > > >> TJG > > --- > > - > > Even if I give the file path as below > > > file = ur'\\?\C:\TestDataSet\DeepPaths > > \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe > > vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP > > athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ > > DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt' > > > I am still getting the exception: > > > Traceback (most recent call last): > > File "C:\JPDump\test.py", line 29, in > > renameStubs(file) > > File "C:\JPDump\test.py", line 12, in renameStubs > > os.chdir (path) > > WindowsError: [Error 206] The filename or extension is too long: u'\\\ > > \?\\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\ > > \DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\ > > \DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\ > > \DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\ > > \DeepPathLevel15\\DeepPathLevel16\\' > > Well, the source for os.chdir under Windows uses the Win32 > SetCurrentDirectoryW API as expected. What is not expected > is that the MS docs for that function: > > http://msdn.microsoft.com/en-us/library/aa365530(VS.85).aspx > > still seem to suggest that you can't exceed MAX_PATH (ie 260) > characters. And indeed, attempting to do a mkdir at the command > line of something longer than that will also fail. > > Hmmm.. maybe the usual advice for naming files \\?\... doesn't > apply to directory paths? > > Do you have an already existing full pathname that long? > > TJG Yes Sir, My application demands me to create deep paths of (1023) long. I've cross checked it and the folder actually exists. -- http://mail.python.org/mailman/listinfo/python-list
Behaviour of os.rename()
Hello all, I got a suspicion on the behaviour of os.rename (src,dst).If the src is the path of a file and dst is a new filename this os.rename() function is infact creating a new file with the dst name in the current working directory and leaving the src as it is. Is this the expected behavior? If i want the actual source file in its orignal location to be renamed without doing os.chdir() to that directory, is that possible? Ex: if my script ren.py contains the following code: os.rename("C:\\Folder1\\Folder2\\file1,file2) and my ren.py is in the folder D:\. Now if I run this script, it is creating file2 in D:\ but I want it in C: \Folder1\Folder2. is that possible? When I checked the normal Windows rename function, it is working to my expectations but I can't use it because my file is in a deep path (>255) which Windows won't support. Thanks in advance, Venu. -- http://mail.python.org/mailman/listinfo/python-list
Re: Problem with os.chdir()
On Mar 11, 7:17 pm, Tim Golden wrote: > venutaurus...@gmail.com wrote: > > On Mar 11, 6:41 pm, Tim Golden wrote: > >> venutaurus...@gmail.com wrote: > >>> On Mar 11, 5:19 pm, Tim Golden wrote: > >>>>> Here is my code snippet which you will be interested in: > >>>> Indeed. > >>>>> file = ur'\\?\C:\\TestDataSet\DeepPaths > >>>>> \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe > >>>>> > >>>>> vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP > >>>>> > >>>>> athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ > >>>>> DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt' > >>>> And what happens if you remove that second double-backslash, > >>>> the one between C: and TestDataSet? > >>>> TJG > >>> --- > >>> - > >>> Even if I give the file path as below > >>> file = ur'\\?\C:\TestDataSet\DeepPaths > >>> \DeepPathLevel01\DeepPathLevel02\DeepPathLevel03\DeepPathLevel04\DeepPathLe > >>> > >>> vel05\DeepPathLevel06\DeepPathLevel07\DeepPathLevel08\DeepPathLevel09\DeepP > >>> > >>> athLevel10\DeepPathLevel11\DeepPathLevel12\DeepPathLevel13\DeepPathLevel14\ > >>> DeepPathLevel15\DeepPathLevel16\DeepPathLevel172.txt' > >>> I am still getting the exception: > >>> Traceback (most recent call last): > >>> File "C:\JPDump\test.py", line 29, in > >>> renameStubs(file) > >>> File "C:\JPDump\test.py", line 12, in renameStubs > >>> os.chdir (path) > >>> WindowsError: [Error 206] The filename or extension is too long: u'\\\ > >>> \?\\C:\\TestDataSet\\DeepPaths\\DeepPathLevel01\\DeepPathLevel02\ > >>> \DeepPathLevel03\\DeepPathLevel04\\DeepPathLevel05\\DeepPathLevel06\ > >>> \DeepPathLevel07\\DeepPathLevel08\\DeepPathLevel09\\DeepPathLevel10\ > >>> \DeepPathLevel11\\DeepPathLevel12\\DeepPathLevel13\\DeepPathLevel14\ > >>> \DeepPathLevel15\\DeepPathLevel16\\' > >> Well, the source for os.chdir under Windows uses the Win32 > >> SetCurrentDirectoryW API as expected. What is not expected > >> is that the MS docs for that function: > > >> http://msdn.microsoft.com/en-us/library/aa365530(VS.85).aspx > > >> still seem to suggest that you can't exceed MAX_PATH (ie 260) > >> characters. And indeed, attempting to do a mkdir at the command > >> line of something longer than that will also fail. > > >> Hmmm.. maybe the usual advice for naming files \\?\... doesn't > >> apply to directory paths? > > >> Do you have an already existing full pathname that long? > > >> TJG > > > Yes Sir, > > My application demands me to create deep paths of (1023) long. > > I've cross checked it and the folder actually exists. > > Well, a little bit of experimentation shows that you can > *create* paths this deep (say, with os.mkdir). But you > can't actually set the current directory to it. So the > next question is: do you actually need to be *in* that > directory, rather than simply to reference it? > > In other words, you can do this (assuming you have a c:\temp): > > > import os > for i in range (1, 15): > os.mkdir (ur"\\?\c:\temp\%s" % "\\".join (100 * "c" for j in range (i))) > > > > But you can't then os.chdir to it. You're hitting the limits of > the OS. Try accessing files directly within the structure > you're using. (ie without chdir-ing there first). > > TJG Sir, My application has to rename a file in that folder.For that I had to do a os.chdir() to that folder. Otherwise if I do a os.rename (deeppath\file1,file2), it is creating a new file in the current working directory with the new name and leaving the original file as it is which is not intended :-(. So, can you suggest me any work around for this? Thank you Venu. -- http://mail.python.org/mailman/listinfo/python-list
Re: Behaviour of os.rename()
On Mar 11, 7:20 pm, Tim Golden wrote: > venutaurus...@gmail.com wrote: > > Hello all, > > I got a suspicion on the behaviour of os.rename > > (src,dst).If the src is the path of a file and dst is a new filename > > this os.rename() function is infact creating a new file with the dst > > name in the current working directory and leaving the src as it is. Is > > this the expected behavior? If i want the actual source file in its > > orignal location to be renamed without doing os.chdir() to that > > directory, is that possible? > > > Ex: if my script ren.py contains the following code: > > > os.rename("C:\\Folder1\\Folder2\\file1,file2) > > > and my ren.py is in the folder D:\. Now if I run this > > script, it is creating file2 in D:\ but I want it in C: > > \Folder1\Folder2. is that possible? > > > When I checked the normal Windows rename function, it is > > working to my expectations but I can't use it because my file is in a > > deep path (>255) which Windows won't support. > > os.rename on windows calls the Windows MoveFile API: > > http://msdn.microsoft.com/en-us/library/aa365239(VS.85).aspx > > Have a look at the details on that page to see what > the limitations / actions are. But remember -- as I've > indicated elsewhere -- to use the ur"\\?\c:\..." form > of the file names. > > And let us know if that works :) > > TJG That actually was an illustration. As you've told in another chain, it isn't working even after appending "\\?\" Thank you, Venu -- http://mail.python.org/mailman/listinfo/python-list
Re: Behaviour of os.rename()
On Mar 11, 7:27 pm, Emile van Sebille wrote: > venutaurus...@gmail.com wrote: > > Hello all, > > I got a suspicion on the behaviour of os.rename > > (src,dst).If the src is the path of a file and dst is a new filename > > this os.rename() function is infact creating a new file with the dst > > name in the current working directory and leaving the src as it is. Is > > this the expected behavior? If i want the actual source file in its > > orignal location to be renamed without doing os.chdir() to that > > directory, is that possible? > > > Ex: if my script ren.py contains the following code: > > > os.rename("C:\\Folder1\\Folder2\\file1,file2) > > os.rename("C:\\Folder1\\Folder2\\file1","C:\\Folder1\\Folder2\\file2") > > Emile Thank you, It worked :-) -- http://mail.python.org/mailman/listinfo/python-list
Problem while copying a file from a remote filer
Hi all, I have to write an application which does a move and copy of a file from a remote machine to the local machine. I tried something like: file = ur"venuwin2008\\C\\4Folders\\Folder02\\Folder002\ \TextFile_06.txt" dest = "C:\\test" shutil.copy(file,dest) But it is throwing an error: Traceback (most recent call last): File "E:\venu\Testing Team\test.py", line 22, in shutil.copy(file,dest) File "C:\Python26\lib\shutil.py", line 88, in copy copyfile(src, dst) File "C:\Python26\lib\shutil.py", line 52, in copyfile fsrc = open(src, 'rb') IOError: [Errno 22] invalid mode ('rb') or filename: u'\\\ \venuwin2008C4FoldersFolder02Folder002\\\ \TextFile_06.txt' Can some one please help me in this regard. Thank you Venu madhav -- http://mail.python.org/mailman/listinfo/python-list
how to identify the file system type of a drive?
hi all, Is there any way to identify the File system type of a drive in python in Windows? Some thing like: C:\ -- NTFS D:\ -- FAT32.. so on.. Thank you, Venu Madhav. -- http://mail.python.org/mailman/listinfo/python-list
Creating 50K text files in python
Hello all, I've an application where I need to create 50K files spread uniformly across 50 folders in python. The content can be the name of file itself repeated 10 times.I wrote a code using normal for loops but it is taking hours together for that. Can some one please share the code for it using Multithreading. As am new to Python, I know little about threading concepts. This is my requiremnt: C:\TestFolder That folder contains 5 Folders.. Folder1, Folder2, Folder3. Folder5 Each folder in turn contains 10 folders: and Each of those folder contains 1000 text files. Please let me know if you are not clear. Thank you, Venu Madhav. -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating 50K text files in python
On Mar 18, 6:16 pm, "venutaurus...@gmail.com" wrote: > Hello all, > I've an application where I need to create 50K files spread > uniformly across 50 folders in python. The content can be the name of > file itself repeated 10 times.I wrote a code using normal for loops > but it is taking hours together for that. Can some one please share > the code for it using Multithreading. As am new to Python, I know > little about threading concepts. > > This is my requiremnt: > > C:\TestFolder > That folder contains 5 Folders.. Folder1, Folder2, Folder3. > Folder5 > Each folder in turn contains 10 folders: > and Each of those folder contains 1000 text files. > > Please let me know if you are not clear. > > Thank you, > Venu Madhav. - I managed to get this code but the problem is main thread exits before the completetion of child threads: class MyThread ( threading.Thread ): def run ( self ): global theVar print 'This is thread ' + str ( theVar ) + ' speaking.' print 'Hello and good bye.' theVar = theVar + 1 time.sleep (4) print 'This is thread ' + str ( theVar ) + ' speaking. again' for x in xrange ( 20 ): MyThread().start() --- I can't use a sleep in the main thread because I don't know when the child threads end. Thank you, venu madhav. -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating 50K text files in python
On Mar 18, 6:35 pm, Peter Otten <__pete...@web.de> wrote: > venutaurus...@gmail.com wrote: > > Hello all, > > I've an application where I need to create 50K files spread > > uniformly across 50 folders in python. The content can be the name of > > file itself repeated 10 times.I wrote a code using normal for loops > > but it is taking hours together for that. Can some one please share > > the code for it using Multithreading. As am new to Python, I know > > little about threading concepts. > > > This is my requiremnt: > > > C:\TestFolder > > That folder contains 5 Folders.. Folder1, Folder2, Folder3. > > Folder5 > > Each folder in turn contains 10 folders: > > and Each of those folder contains 1000 text files. > > > Please let me know if you are not clear. > > > Thank you, > > Venu Madhav. > > I've just tried it, creating the 50,000 text files took 17 seconds on my not > very fast machine. Python is certainly not the bottleneck here. > > Peter Really... I just can't beleive it. I am running my scirpt on an INTEL Core2duo CPU machine with 2GB of RAM. I've started it two hours back, but still it is running. This is how my code looks like def createFiles(path): m.write(strftime("%Y-%m-%d %H:%M:%S") +" Creating files in the folder "+path+"\n") global c global d os.chdir (path) k = 1 for k in range (1,1001): p = "%.2d"%(k) FName = "TextFile"+c+"_"+d+"_"+p+".txt" l =1 for l in range(1 , 11): os.system ("\"echo "+FName+" >> "+FName+"\"") l = l +1 k = k+1 MainPath = "C:\\Many_5_1KB" try: os.mkdir (MainPath) m.write(strftime("%Y-%m-%d %H:%M:%S") +" Created the base directory \n") except: m.write(strftime("%Y-%m-%d %H:%M:%S") +" base directory already exists\n") os.chdir (MainPath) for i in range (1 , 6): j = 1 c = "%.2d"%(i) FolderName ="Folder"+c try: os.mkdir (FolderName) m.write(strftime("%Y-%m-%d %H:%M:%S") +" Created the folder "+FolderName+"\n") except: m.write(strftime("%Y-%m-%d %H:%M:%S") +" Folder "+FolderName+" already exists \n") os.chdir (FolderName) path = os.getcwd () #createFiles(path) for j in range ( 1 , 11): d = "%.2d"%(j) FolderName = "Folder"+c+"_"+d try: os.mkdir (FolderName) m.write(strftime("%Y-%m-%d %H:%M:%S") +" Created the folder "+FolderName+"\n") except: m.write(strftime("%Y-%m-%d %H:%M:%S") +" the folder "+FolderName+" exists \n") os.chdir (FolderName) path = os.getcwd () createFiles(path) os.chdir ("..") j = j + 1 os.chdir ("..") i = i + 1 Can you please let me know where do I have to modify it, to make it faster. Thank you, Venu Madhav -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating 50K text files in python
On Mar 18, 6:58 pm, Marco Mariani wrote: > venutaurus...@gmail.com wrote: > > for k in range (1,1001): > ... > > k = k+1 > > Man, you have a trouble with loops, all over. But the situation demands it.:-( I've to create 5 folders and 10 folders in each of them. Each folder again should contain 1000 text files. -- http://mail.python.org/mailman/listinfo/python-list
Obtaining the attributes and properties of a folder recursively.
Hello all, Is there any way to list out all the properties (name, type, size) and attributes( Accesstime, mod time, archived or readonly etc) of a folder and its contents recursively. Should I need ot go inside each and every directory to list them? This has to be for Windows. I have to obtain the following attriubtes of all the files recursively in a directory: NAME\ FILE CREATION TIME \ MODIFICATION TIME \ ACCESS TIME \ ATTRIBUTES \ ACLs \ File SIze \ Thank you, Venu Madhav -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
On Mar 20, 1:58 pm, Tino Wildenhain wrote: > venutaurus...@gmail.com wrote: > > Hello all, > > Is there any way to list out all the properties (name, > > type, size) and attributes( Accesstime, mod time, archived or readonly > > etc) of a folder and its contents recursively. Should I need ot go > > inside each and every directory to list them? This has to be for > > Windows. > > I have to obtain the following attriubtes of all the files > > recursively in a directory: > > > NAME\ FILE CREATION TIME \ MODIFICATION TIME \ ACCESS TIME \ > > ATTRIBUTES \ ACLs \ File SIze \ > > Just some hints you might want to check: > > os.walk > > >>> help(os.walk) > > and os.stat > > please see the example for os.walk - this > would work on every platform supported by > python. > > for acls, a little more work would be needed > if you want something filesystem specific but > posix style information is included with stat() > > Regards > Tino > > smime.p7s > 4KViewDownload Thanks for your suggestion. By the way the attachment which have added has some unknown file extension. May I know how can I view it? -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
On Mar 20, 5:09 pm, Tim Golden wrote: > Tino Wildenhain wrote: > > Tim Golden wrote: > > ... > >> and do the following: > > >> > >> from winsys import fs > > >> for f in fs.flat ("c:/temp"): > >> f.dump () > > ^ eeek! > > Was the k! for the space before the bracket > (which, for some unaccountable reason disturbs > some people)? Or for the idea of dumping data > out? > > This is what it looks like for one (random) file: > > > Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC > Type "help", "copyright", "credits" or "license" for>>> from winsys import fs > >>> fs.file ("c:/temp/t.py").dump () > > { > c:\temp\t.py > { > c:\temp\t.py > parts: [u'?\\c:\\', u'temp', u't.py'] > root: \\?\c:\ > dirname: \temp > path: \\?\c:\\temp > filename: t.py > parent: \\?\c:\temp > } > readable: True > id: 260191347677670224354611 > n_links: 1 > created_at: 2008-10-27 09:45:09 > accessed_at: 2009-03-20 08:57:25 > written_at: 2009-03-20 08:57:25 > uncompressed_size: 1170 > size: 1170 > Attributes: > { > ARCHIVE => True > COMPRESSED => False > DIRECTORY => False > ENCRYPTED => False > HIDDEN => False > NORMAL => False > NOT_CONTENT_INDEXES => False > OFFLINE => False > READONLY => False > REPARSE_POINT => False > SPARSE_FILE => False > SYSTEM => False > TEMPORARY => False > VIRTUAL => False > } > Security: > control: > { > DACL_AUTO_INHERITED > SELF_RELATIVE > DACL_PRESENT > } > owner: VOUK\goldent > dacl: > { > inherited: True > { > trustee: VOUK\goldent > access: 1000 > type: ACCESS_ALLOWED > } > { > trustee: BUILTIN\Administrators > access: 1000 > type: ACCESS_ALLOWED > flags: > { > INHERITED > } > } > { > trustee: NT AUTHORITY\SYSTEM > access: 1000 > type: ACCESS_ALLOWED > flags: > { > INHERITED > } > } > { > trustee: VOUK\goldent > access: 1000 > type: ACCESS_ALLOWED > flags: > { > INHERITED > } > } > { > trustee: BUILTIN\Users > access: 100101010100 > type: ACCESS_ALLOWED > flags: > { > INHERITED > } > } > }} > > > > TJG Thank you for your suggestion but.. I'll have around 1000 such files in the whole directory and it becomes hard to manage such output because again I've to take this snapshot before backing up the data and have to do the same and compare both when the data gets restored, just to verify whether the restore happened successfully or not. Thank you, Venu Madhav -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
On Mar 20, 6:58 pm, Tim Golden wrote: > venutaurus...@gmail.com wrote: > > Thank you for your suggestion but.. I'll have around 1000 such files > > in the whole directory and it becomes hard to manage such output > > because again I've to take this snapshot before backing up the data > > and have to do the same and compare both when the data gets restored, > > just to verify whether the restore happened successfully or not. > > The .dump is simply a way of seeing quickly what the data is. > If you want to store is somewhere (.csv or whatever), you can > just select the attributes you want. Note, though, that ACLs > are tricky to compare. Something like the following might do > what you want, perhaps? > > > import os > import csv > from winsys import fs > > with open ("info.csv", "wb") as f: > writer = csv.writer (f) > for f in fs.flat ("c:/temp/cabsdk"): > print f > writer.writerow ([ > f, > f.created_at, > f.written_at, > f.attributes, > f.security (), > f.size > ]) > > os.startfile ("info.csv") > > > This uses the security's SDDL representation, which while > opaque does at least give you a before-and-after check. > > TJG Thank you Sir for your reply. It is working for me. But is failing if I have Unicode characters in my path. I tried giving a 'u' in front of the path but still it fails at f.createdat. Does it support Unicode Characters? This the traceback which I got while running the above python script on my data: --- \\?\C:\JPDump\AGIT_FSDM\Unicode\Arabic files\ArabicÖ°××××אּשּׁï ïïïïכּטּךּאָשּׁïïװײ״××¦×ª× Traceback (most recent call last): File "C:\MFDump\snapshot.py", line 10, in f.created_at, File "C:\Python26\Lib\site-packages\winsys\fs.py", line 476, in _get_created_at return utils.from_pytime (wrapped (win32file.GetFileAttributesEx, self._filepath)[1]) File "C:\Python26\Lib\site-packages\winsys\exceptions.py", line 26, in _wrapped raise exception (errmsg, errctx, errno) x_invalid_name: ('The filename, directory name, or volume label syntax is incorrect.', 'GetFileAttributesEx', 123) - Thank you, Venu Madhav, -- http://mail.python.org/mailman/listinfo/python-list
Re: Obtaining the attributes and properties of a folder recursively.
On Mar 21, 3:05 pm, Tim Golden wrote: > venutaurus...@gmail.com wrote: > > Thank you Sir for your reply. It is working for me. But is failing if > > I have Unicode characters in my path. I tried giving a 'u' in front of > > the path but still it fails at f.createdat. Does it support Unicode > > Characters? > > > This the traceback which I got while running the above python script > > on my data: > > --- > > \\?\C:\JPDump\AGIT_FSDM\Unicode\Arabic files\Arabicְדזךמאּשּׁתּ > > פּפֿשּﭏכּטּךּאָשּׁבֿפֿװײ״טצתא > > In fact, to give me something to test against, would you > be able to send me the result of running this code, please? > It's just listing the names of the files under that particular > directly, encoded as utf8 so they'll survive transit: > > > import os > from winsys import fs > > PATH = r"\\?\C:\JPDump\AGIT_FSDM\Unicode\Arabic files" > f = open ("arabic-files.txt", "wb") > for filename in fs.listdir (PATH): > f.write (filename.encode ("utf8") + "\r\n") > > f.close () > os.startfile ("arabic-files.txt") > > > > Thanks > TJG This is the output for your code Sir. But I think os.stat is sufficient to satisfy all my requirements. May be we just have to make the path itself a Unicode path. Arabicְדזךמאּשּׁתּפּפֿשּﭏכּטּךּאָשּׁבֿפֿװײ״טצתא Arabicְדזךמאּשּׁתּפּפֿשּﭏכּטּךּאָשּׁבֿפֿװײ״טצתא.doc Arabicְדזךמאּשּׁתּפּפֿשּﭏכּטּךּאָשּׁבֿפֿװײ״טצתאnew.doc الأبجدي.txt تعلم اللغة الإيطالية مجان.doc دروس مجانية في اللغة الإنجليزي.txt دروس مجانية في اللغة الإنجليزي1.txt Thank you, Venu -- http://mail.python.org/mailman/listinfo/python-list
Creating huge data in very less time.
Hello all, I've a requirement where I need to create around 1000 files under a given folder with each file size of around 1GB. The constraints here are each file should have random data and no two files should be unique even if I run the same script multiple times. Moreover the filenames should also be unique every time I run the script.One possibility is that we can use Unix time format for the file names with some extensions. Can this be done within few minutes of time. Is it possble only using threads or can be done in any other way. This has to be done in Windows. Please mail back for any queries you may have, Thank you, Venu Madhav. -- http://mail.python.org/mailman/listinfo/python-list
Re: Creating huge data in very less time.
On Mar 31, 1:15 pm, Steven D'Aprano wrote: > On Mon, 30 Mar 2009 22:44:41 -0700, venutaurus...@gmail.com wrote: > > Hello all, > > I've a requirement where I need to create around 1000 > > files under a given folder with each file size of around 1GB. The > > constraints here are each file should have random data and no two files > > should be unique even if I run the same script multiple times. > > I don't understand what you mean. "No two files should be unique" means > literally that only *one* file is unique, the others are copies of each > other. > > Do you mean that no two files should be the same? > > > Moreover > > the filenames should also be unique every time I run the script. One > > possibility is that we can use Unix time format for the file names > > with some extensions. > > That's easy. Start a counter at 0, and every time you create a new file, > name the file by that counter, then increase the counter by one. > > > Can this be done within few minutes of time. Is it > > possble only using threads or can be done in any other way. This has to > > be done in Windows. > > Is it possible? Sure. In a couple of minutes? I doubt it. 1000 files of > 1GB each means you are writing 1TB of data to a HDD. The fastest HDDs can > reach about 125 MB per second under ideal circumstances, so that will > take at least 8 seconds per 1GB file or 8000 seconds in total. If you try > to write them all in parallel, you'll probably just make the HDD waste > time seeking backwards and forwards from one place to another. > > -- > Steven That time is reasonable. The randomness should be in such a way that MD5 checksum of no two files should be the same.The main reason for having such a huge data is for doing stress testing of our product. -- http://mail.python.org/mailman/listinfo/python-list
HTML Conversion in python
Hello All, Is there any library defined in Python which can convert a given text file into a html page. Basically, I require functions for creating tables or filling background colours for the html pages etc instead of writing each and every tag in my script.. Thank you, Venu Madhav. -- http://mail.python.org/mailman/listinfo/python-list
Calling user defined functions from a different script..
Hello all, I have a situation where I need to call functions present in a different script whose hierarchy is something like below: C:\Pythonlib\uitl\script1.py {Place where my functions definitions are present} C:\Scripts\script2.py { Place where function calls are made} In such a situation how can I import functions from script1.py and use it in script2.py. Please let me know if you need any further details. Thank you, Venu Madhav. -- http://mail.python.org/mailman/listinfo/python-list
Passing parameters for a C program in Linux.
Hi all, I have to write an automted script which will test my c program. That program when run will ask for the commands. For example: local-host# ./cli Enter 1 for add Enter 2 for sub Enter 3 for mul 1---Our option Enter two numbers 44 33 Our option Result is 77 As shown in the above example it lists all the options and waits for user input and once given, it does some operations and waits for some more. This has to be automated. Can someone give suggestions how to do this in Python (Linux Platform in particular). Thank you, Venu. -- http://mail.python.org/mailman/listinfo/python-list
Re: Passing parameters for a C program in Linux.
On Jun 30, 5:42 pm, Petr Messner wrote: > Hi, > > this can be done using module "subprocess"; there is also function > popen() in module "os" and module popen2, but they are deprecated > since Python 2.6. > > PM > > 2009/6/30 venutaurus...@gmail.com : > > > Hi all, > > I have to write an automted script which will test my c > > program. That program when run will ask for the commands. For example: > > > local-host# ./cli > > Enter 1 for add > > Enter 2 for sub > > Enter 3 for mul > > 1 ---Our option > > Enter two numbers > > 44 33 Our option > > Result is 77 > > > As shown in the above example it lists all the options and waits for > > user input and once given, it does some operations and waits for some > > more. This has to be automated. > > > Can someone give suggestions how to do this in Python (Linux Platform > > in particular). > > > Thank you, > > Venu. > > -- > >http://mail.python.org/mailman/listinfo/python-list > > Can you give some more explanation about how exactly this can be done.. Thanks for reply, Venu -- http://mail.python.org/mailman/listinfo/python-list