Script Center > Scripting Forums > The Official Scripting Guys Forum! > Creating folder using part of filename!
Ask a questionAsk a question
 

QuestionCreating folder using part of filename!

  • Saturday, November 07, 2009 2:47 AMMLev46 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi,
    I am new to these script and so I need help!!!

    These are filenames (karaoke songs) that resides in a folder with the artist's name (3 Doors Down):
    CB30054-13 - 3 Doors Down - Here By Me.zip
    CBE3-25-12 - 3 Doors Down - Be Like That.zip
     
    All my karaokes are named in this format:  Song ID - Artist - Song Title.zip
    All karaokes for one Artist are in one folder named with the Artist name.
    So in my folder called: 3 Doors Down, I have all their songs. I can have different
    Song ID for the same Song Title. I want a script that will move all the files with the same
    Song Titles in to one folder using that Song Title for the folder name. All the new created folders needs
    to resides in the original (3 Doors Down) folder.
     
    Shortly:
    - I want to use the song title (When I'm Gone) and create a folder using that name.
    - Then, move these files in their proper folder just created

    Thank you for your help,
    Michel

All Replies

  • Sunday, November 08, 2009 7:16 AMhydn Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
     Firstly, im new to vbscript. so i just regard your question as homework, lol, below just for your reference

    ---------------------------------------------------------------------------
    Dim f,x,n,a,b,newFolder
    ' your songs folder path
       x="C:\songs\3 Doors Down\"
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set f = fso.GetFolder(x)

     For each file in f.files
       n=fso.getfilename(file)
       a=split(n,".",2,1)
       b=split(a(0)," - ",-1,0)
       Set newFolder=fso.createfolder(x&b(2))
       fso.movefile file,newFolder&"\"
     Next
    ---------------------------------------------------------------------------

    -hayden
  • Sunday, November 08, 2009 3:17 PMarectech Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I wonder if this powershell will work for you...

    # Use content of source directory to create new directories
    # and copy files into the new directory tree

    $SourcePath = "$home\Desktop\Music"
    $TargetPath = "$home\Desktop\OrganizedMusic"

    ForEach($Line in (gci $SourcePath -Include *.zip -Recurse )){ 
      $Folder = $Line.Name.Split("-")[-1]
      $Folder = $Folder.Split(".")[0]
     
       If (!(Test-Path -path "$TargetPath\$Folder")) {
         New-Item "$TargetPath\$Folder" -Type Directory
       }

     Copy-Item $Line "$TargetPath\$Folder"

    }