#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    35
    Rep Power
    10

    need somebody to help me create a script


    the thing is like this:
    i have 90 folders, each one with a couple of files inside

    i want a script that put all the files in one folder, but i want to add to each file the folder name to the file name.

    for example i have "Adams, Douglas" folder with files "book 1" book 2" book 3"
    and i want to get "Adams, Douglas - book 1" , "Adams, Douglas - book 2" "Adams, Douglas - book ..."

    i dont know how to manage files with python so thats why i didnt made anything

    thanks for your help
  2. #2
  3. slightly insane code guru
    Devshed Novice (500 - 999 posts)

    Join Date
    Jul 2004
    Location
    Indianapolis, IN
    Posts
    871
    Rep Power
    17
    http://python.org/doc/2.3.4/lib/os-file-dir.html
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2004
    Posts
    73
    Rep Power
    10
    #you know there's nothing like a standard way of doing this, but I would create a script like the following (Recursive)

    from dircache import listdir
    def Write(Dir,Name,Destination="AnyFolder/"):
    f=open(Dir+Name,'rb')
    Data=f.read()
    f.close()
    Dir = Dir.replace("/","-")
    f=open(Destination + Dir + Name,'wb')
    f.write(Data)
    f.close()
    def DeepCopy(Dir,Destination="AnyFolder/"):
    DirVar = listdir(Dir)
    for i in DirVar:
    try:
    listdir(i)
    DeepCopy(Dir+i+"/")
    except:
    Write(Dir,i)
    Directory="foo/"
    DeepCopy(Directory)

IMN logo majestic logo threadwatch logo seochat tools logo