from the docs:
os.rename(src, dst)¶Rename the file or directory src to dst. If dst is a
directory, OSError will be raised.
I did read that, thank you. That is why I asked how to override, as I
understood that Python was functioning exactly as intended.
It seems what you wan to
do is
I see, thanks. So I was sending it four values apparently. I did not
understand the error message.
No, you're sending it two values: a tuple, and a string. It wants two
strings. Thus the error. If you had sent it four values, you'd have gotten
a different error.
I see. For some reason I
Why is the print below commented out?
for f in file:
toMove =oot + / + f
#print toMove
os.rename(toMove, currentDir)
I was testing, and it was not longer needed. It was returning what I
expected. Note that print can only be used to test that the value
matches what
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Hello,
: I use this one-liner for moving photos nested a single folder deep
: into the top-level folder:
:
: find * -name *.jpg | awk -F/ '{print mv $0,$1-$2}' | sh
I would add a few different features to this 'find' to make it a bit
more
All right, I've got it! This script will move all files of
subdirectories into cwd.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
currentDir = os.getcwd()
filesList = os.walk(currentDir)
for rootDirs, folders, files in filesList:
for f in files:
toMove =
When combining directory paths, it's generally safer to use
os.path.join()
As KDE/Dolphin runs on windows this is even more important as it will
sort out the directory separator (/ vs \) for you.
Added, thanks!
Some added reading on os.path can be found on Doug's excellent PyMOTW
[1].
I use this one-liner for moving photos nested a single folder deep
into the top-level folder:
find * -name *.jpg | awk -F/ '{print mv $0,$1-$2}' | sh
You could miss out the awk and use the exec option of find...
Or miss out the shell and use the system() function of awk.
The truth is
I would add a few different features to this 'find' to make it a bit
more resistant to failure, although this sort of solution is always
subject to the somebody else is toying with my filesystem race
condition.
find $srcdir -depth -type f -print0 \
| xargs --null --no-run-if-empty -- \
Here is the revised version:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
currentDir = os.getcwd()
i = 1
filesList = os.walk(currentDir)
for rootDirs, folders, files in filesList:
for f in files:
if (rootDirs!=currentDir):
toMove = os.path.join(rootDirs, f)
Dotan Cohen wrote:
Here is the revised version:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
currentDir = os.getcwd()
i = 1
filesList = os.walk(currentDir)
for rootDirs, folders, files in filesList:
Actual the first item in the tuple (returned by os.walk) is singular (a
string), so I
Actual the first item in the tuple (returned by os.walk) is singular (a
string), so I might call it rootDir. Only the other two needed to be
changed to plural to indicate that they were lists.
I did discover this, too. I wanted to finish with the code at hand
before I started experimenting
I use this one-liner for moving photos nested a single folder deep
into the top-level folder:
find * -name *.jpg | awk -F/ '{print mv $0,$1-$2}' | sh
I would like to expand this into an application that handles arbitrary
nesting and smart rename, so I figure that Python is the language that
I
What fine manual should I be reading? I am not asking for
code, rather just a link to the right documentation.
You'll definitely want to explore the os module, part of Python's built-in
standard library.
http://docs.python.org/library/os.html
On 12 April 2010 17:23, Serdar Tumgoren zstumgo...@gmail.com wrote:
What fine manual should I be reading? I am not asking for
code, rather just a link to the right documentation.
You'll definitely want to explore the os module, part of Python's built-in
standard library.
On Tue, 13 Apr 2010 12:11:30 am Dotan Cohen wrote:
I use this one-liner for moving photos nested a single folder deep
into the top-level folder:
find * -name *.jpg | awk -F/ '{print mv $0,$1-$2}' | sh
I would like to expand this into an application that handles
arbitrary nesting and smart
Lovely??? What on earth does it do? It's worse than Perl code!!!
*half a wink*
Like a good wife, it does what I need even if it is not pretty on the
eyes. _That_ is lovely!
(I can get away with that, I'm married to a redhead.)
See the shell utilities module:
import shutil
It overwrites
On 12 April 2010 20:12, Sander Sweers sander.swe...@gmail.com wrote:
On 12 April 2010 18:28, Dotan Cohen dotanco...@gmail.com wrote:
However, it fails like this:
$ ./moveUp.py
Traceback (most recent call last):
File ./moveUp.py, line 8, in module
os.rename(f, currentDir)
TypeError:
All right, I have gotten quite a bit closer, but Python is now
complaining about the directory not being empty:
✈dcl:test$ cat moveUp.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
currentDir = os.getcwd()
filesList = os.walk(currentDir)
for root, folder, file in filesList:
for f in
On Mon, Apr 12, 2010 at 1:21 PM, Dotan Cohen dotanco...@gmail.com wrote:
All right, I have gotten quite a bit closer, but Python is now
complaining about the directory not being empty:
✈dcl:test$ cat moveUp.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
currentDir = os.getcwd()
Dotan Cohen wrote:
On 12 April 2010 20:12, Sander Sweers sander.swe...@gmail.com wrote:
On 12 April 2010 18:28, Dotan Cohen dotanco...@gmail.com wrote:
However, it fails like this:
$ ./moveUp.py
Traceback (most recent call last):
File ./moveUp.py, line 8, in module
os.rename(f,
Dotan Cohen wrote:
All right, I have gotten quite a bit closer, but Python is now
complaining about the directory not being empty:
✈dcl:test$ cat moveUp.py
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
currentDir =s.getcwd()
filesList =s.walk(currentDir)
for root, folder, file in
On 12 April 2010 22:13, Dave Angel da...@ieee.org wrote:
When combining directory paths, it's generally safer to use
os.path.join()
As KDE/Dolphin runs on windows this is even more important as it will
sort out the directory separator (/ vs \) for you.
Some added reading on os.path can be
Dotan Cohen dotanco...@gmail.com wrote
I use this one-liner for moving photos nested a single folder deep
into the top-level folder:
find * -name *.jpg | awk -F/ '{print mv $0,$1-$2}' | sh
You could miss out the awk and use the exec option of find...
Or miss out the shell and use the
23 matches
Mail list logo