Hello there :), i have bunch of pictures which the title is like this Name-LastName-year-category-.... what i want to do is sort them all in folders which will have only their Name-LastName and all pics with that name go in that folder. Is there some tool for this job to be done easily? Or maybe some code that i can setup?

I hope you understood me. if not feel free to say ill try to explain better, thank you :)

Okay, nope am not building an app, i need to get task done, i dont want to do it manually because its more than 20.000 pictures it would take alot. The images are all stored in one folder.

Am searching for code or program that can get the task donee.

Example:

Images Title
Stefan-Rafa-400x500-123uirjht5-1.jpg
Stefan-Rafa-300x300-12a32s-1.jpg
Stefan-Rafa-100-123uirjht5-1.jpg
John-Doe-400x500-123uirjht5-1.jpg
John-Doe-3-1423555-400x200.jpg
John-Doe-300x300-123uirjht5-1.jpg

Create foder and transfer
Folder name > Stefan-Rafa
Folder name > John-Doe

Files Inside folder Stefan-Rafa:
Stefan-Rafa-400x500-123uirjht5-1.jpg
Stefan-Rafa-300x300-12a32s-1.jpg
Stefan-Rafa-100-123uirjht5-1.jpg

Files Inside folder John-Doe:
John-Doe-400x500-123uirjht5-1.jpg
John-Doe-3-1423555-400x200.jpg
John-Doe-300x300-123uirjht5-1.jpg

OS: Windows 10

Nope its way too much work if am doing it manual 70k+ files.

I don't normaly just provide code but

  1. It's pretty simple
  2. I'm really bored

Copy the following code into a file named SortFiles.vbs in the same folder containing your images. If you run it by

cscript sortfiles.vbs

the script will create the required folders under the current folder and move the files into each folder as requested. I suggest that you make a copy of the images in another folder for safe-keeping before you run the script. You can always delete the copy after you see if the results are what you wanted.

set fso = CreateObject("Scripting.FileSystemObject")

for each file in fso.GetFolder(".").Files
    if lcase(fso.GetExtensionName(file.Name)) = "jpg" Then
        flds = Split(file.Name,"-")
        if Ubound(flds) >= 2 Then
            folder = flds(0) & "-" & flds(1) & "\"
            if not fso.FolderExists(folder) Then
                Wscript.Echo "Creating folder",folder
                fso.CreateFolder(folder)
            end if
            Wscript.Echo "Moving:",file.Name
            Wscript.Echo "    To:",folder
            fso.MoveFile file.Name, folder
        end if
    end if
next

I created .txt file named sortfiles saved the code inside it and renamed to sortfiles.vbs the file sortfiles.vbs has created, I have runed it but nothing happens. Will the code proceed working if there are some images not containing the same order of images title?

The script looks at all jpg files in the folder. If the file name has at least three fields separated by "-" then it creates a folder name from the first two fields and moves the file. In other words, it will process

a-b-c.jpg
a-b-c-d.jpg
a-b-c-d-e.jpg
etc

but not

a-b.jpg

If you replace

fso.MoveFile file.Name, folder

with

'fso.MoveFile file.Name, folder

(commented out) then you can run the script to see what files would be moved without actually moving them. When you say "nothing happens" what exactly do you mean? What is echoed back in the command window? Did you save the script file in the same folder as your jpg files? I tested the script by creating the files

Stefan-Rafa-400x500-123uirjht5-1.jpg
Stefan-Rafa-300x300-12a32s-1.jpg
Stefan-Rafa-100-123uirjht5-1.jpg
John-Doe-400x500-123uirjht5-1.jpg
John-Doe-3-1423555-400x200.jpg
John-Doe-300x300-123uirjht5-1.jpg

and running the script. It worked as I understand you wanted it to.

D:\test>dir /s
 Volume in drive D is D-Data
 Volume Serial Number is 366A-6FA3

 Directory of D:\test

2017-08-21  08:14    <DIR>          .
2017-08-21  08:14    <DIR>          ..
2017-08-21  08:14                 0 John-Doe-300x300-123uirjht5-1.jpg
2017-08-21  08:14                 0 John-Doe-3-1423555-400x200.jpg
2017-08-21  08:14                 0 John-Doe-400x500-123uirjht5-1.jpg
2017-08-21  08:14               613 sortfiles.vbs
2017-08-21  08:14                 0 Stefan-Rafa-100-123uirjht5-1.jpg
2017-08-21  08:14                 0 Stefan-Rafa-300x300-12a32s-1.jpg
2017-08-21  08:14                 0 Stefan-Rafa-400x500-123uirjht5-1.jpg
               7 File(s)            613 bytes

     Total Files Listed:
               7 File(s)            613 bytes
               2 Dir(s)  916,313,260,032 bytes free

D:\test>cscript sortfiles.vbs
Creating folder John-Doe\
Moving: John-Doe-3-1423555-400x200.jpg
    To: John-Doe\
Moving: John-Doe-300x300-123uirjht5-1.jpg
    To: John-Doe\
Moving: John-Doe-400x500-123uirjht5-1.jpg
    To: John-Doe\
Creating folder Stefan-Rafa\
Moving: Stefan-Rafa-100-123uirjht5-1.jpg
    To: Stefan-Rafa\
Moving: Stefan-Rafa-300x300-12a32s-1.jpg
    To: Stefan-Rafa\
Moving: Stefan-Rafa-400x500-123uirjht5-1.jpg
    To: Stefan-Rafa\

D:\test>dir /s
 Volume in drive D is D-Data
 Volume Serial Number is 366A-6FA3

 Directory of D:\test

2017-08-21  08:15    <DIR>          .
2017-08-21  08:15    <DIR>          ..
2017-08-21  08:15    <DIR>          John-Doe
2017-08-21  08:15    <DIR>          Stefan-Rafa
2017-08-21  08:14               613 sortfiles.vbs
               1 File(s)            613 bytes

 Directory of D:\test\John-Doe

2017-08-21  08:15    <DIR>          .
2017-08-21  08:15    <DIR>          ..
2017-08-21  08:14                 0 John-Doe-300x300-123uirjht5-1.jpg
2017-08-21  08:14                 0 John-Doe-3-1423555-400x200.jpg
2017-08-21  08:14                 0 John-Doe-400x500-123uirjht5-1.jpg
               3 File(s)              0 bytes

 Directory of D:\test\Stefan-Rafa

2017-08-21  08:15    <DIR>          .
2017-08-21  08:15    <DIR>          ..
2017-08-21  08:14                 0 Stefan-Rafa-100-123uirjht5-1.jpg
2017-08-21  08:14                 0 Stefan-Rafa-300x300-12a32s-1.jpg
2017-08-21  08:14                 0 Stefan-Rafa-400x500-123uirjht5-1.jpg
               3 File(s)              0 bytes

     Total Files Listed:
               7 File(s)            613 bytes
               8 Dir(s)  916,313,260,032 bytes free

D:\test>

Yes the file sortfiles.vbs is placed in the folder where all the images are. BTW when i dubleclick the sortfiles.vbs exactly nothing happens, i doesn't get command windows open and no folder is created. Maybe am doing something wrong or i have to install something to run this script?

EDIT: I have mistaken in the file format, the files are all .jpeg so i got it running! Now my question is i get a popup window telling me that folder is created with the related name and every picture that needs to go inside the folder i get a popup asking me to do it, so i need to press "OK" every time new popup comes out. How do i make this automated? Othervise that Enter button will suffer... AND my finger too :P

Okay i got it, but it sems like i have titles with just a-b.jpeg is it possible to process like that also ?

@Stefen, while I see how, you must dig in a little here as your files, your responsibility. Blindly using scripts is something I don't advise.

Did you notice this line?
` if Ubound(flds) >= 2 Then

That section could be changed to just > 2 and then you could copy that section to have a handler for = 2 and alter the code to handle just the a-b.jpeg as you wish.

when i dubleclick the sortfiles.vbs exactly nothing happens

That's because you didn't read the instructions. I told you to run it by

cscript sortfiles.vbs

Apparently I was unclear in that you do this from the command line. vbScript files are executed by either cscript.exe (console) or wscript.exe (window). The default is wscript.exe and when run with the default, each echo pops up a msgbox. If you run it the way that I suggested you force it to run under cscript.exe and each echo writes a line to the console window. You can force cscript.exe to be the default by running (from a console window as Administrator)

cscript //h:cscript //nologo //s

Following that you can run the script from the command line by simply typing

sortfiles

It will take longer to run with all the echo statements but it's worthwhile in case something goes wrong - you can see exactly where it stops.

Okay i got it, but it sems like i have titles with just a-b.jpeg is it possible to process like that also ?

It certainly is but you didn't include that in the original spec. You could change the code to

set fso = CreateObject("Scripting.FileSystemObject")

for each file in fso.GetFolder(".").Files

    ext = lcase(fso.GetExtensionName(file.Name))

    if ext = "jpg" or ext = "jpeg" Then
        flds = Split(file.Name,"-")
        if Ubound(flds) >= 2 Then
            folder = flds(0) & "-" & flds(1) & "\"
            if not fso.FolderExists(folder) Then
                Wscript.Echo "Creating folder",folder
                fso.CreateFolder(folder)
            end if
            Wscript.Echo "Moving:",file.Name
            Wscript.Echo "    To:",folder
            fso.MoveFile file.Name, folder
        end if
    end if

next

or (what I would do), make your file names more consistent by typing

ren *.jpeg *.jpg

so they all have the same extension.

Let me get back to you with the a-b.jpeg variant. The above code won't handle that yet. Before I do that, how does the other file name work? According to your original spec, this allows for something like

john-doe.jpg

Basically, only one file per person. How many files of this type do you have?

Since i didnt know the scripting language i downloaded program and added suffix at the end -asd and with that i made all images titles a-b-c.jpg and runned the script. The script finished its job great! Thank you, you two @rproffitt @Reverend Jim :)

Thanks Jim! - I needed it as well!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.