logo elektroda
logo elektroda
X
logo elektroda

Script for Organizing Smartphone Photos into Folders by Date: Creating Directories & Copying Files

skorik 15681 16
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 16691715
    skorik
    Level 12  
    I have this problem:
    I rip photos from smartphones to one folder.
    I need a script that puts files (photos) in the directories it creates.
    The directory names that would be: year. month. day.
    To create these folders, the script would have to use the image file property: Date Taken or get it by name. And one folder for a different number of files - sometimes for one and sometimes for several hundred.
    The most common file names are (example):
    20170325_104914 or
    IMG_20170825_204256316 (phone dependent)

    Is there anyone able to create such a script (the point is to save it in a .bat file)
  • ADVERTISEMENT
  • Helpful post
    #2 16692030
    clubs
    Level 38  
    Hello

    Put it in the photo catalog
    Code: Dos
    Log in, to see the code
  • #3 16692214
    skorik
    Level 12  
    Cool.
    The script works fine.
    What needs to be changed to have dots separating the year, month and day in the folder name?
  • Helpful post
    #4 16692809
    clubs
    Level 38  
    Code: Dos
    Log in, to see the code
  • #5 16692924
    skorik
    Level 12  
    Everything works fine.
    Thank you very much.
    For so many years, many hours lost in manual sorting ...
    And it was enough to ask on the electrode :)
  • ADVERTISEMENT
  • #6 16940055
    husk123
    Level 9  
    Hi,
    I will connect to the topic, because I have a similar problem and also need help writing the script.
    I have some example files in the directory:
    aaaa.xxx
    bbbb.xxx
    cccc.xxx
    cccc.xxy
    dddd.yyy
    dddd.xxy
    dddd.xxz
    eeee.zzz
    ffff.zzz
    ffff.xxy
    I would like the script to create the directories aaaa, bbbb, cccc, dddd, eeee and ffff based on the files, and copy the files to them to aaaa - aaaa.xxx; to bbbb - bbbb.xxx; to cccc - cccc.xxx and cccc.xxy; to dddd - dddd.xxx, dddd.xxy and dddd.xxz; to eeee - eeee.zzz; a to ffff - ffff.zzz and ffff.xxy.
    So far I have been able to spit all files with the DIR command into the csv file (dir / b> file.csv) and then in Excel I divided the file names into name and extension. I was removing takes and using the joins.texts function for the command, creating one to create a directory based on name and the other to copy files into a directory based on name. Unfortunately, this method is also time-consuming and not very versatile.
  • #7 16940370
    clubs
    Level 38  
    Hello
    Should you copy or move?
  • #8 16941005
    husk123
    Level 9  
    I actually wrote that he copied, but I mean he would transfer them. If the script was similar to the above, I could fix xcopy / copy on move, but plus for perceptiveness. ;) Alternatively, if you could manage to include the four-character extensions and the fact that there are spaces in the filename and different lengths of the filenames. I started trying something myself and only made myself a bigger mess. I have created a lot of empty directories that are components of file names. A request to describe the script as well - I prefer a fishing rod to a fish.
  • #9 16942379
    clubs
    Level 38  
    Hello
    Put the bat in the directory where you have these files
    Code: Dos
    Log in, to see the code
  • ADVERTISEMENT
  • #10 16945863
    husk123
    Level 9  
    Thanks,
    For those who would like to use the script for something else.
    @Echo. off - disable command display
    setlocal enabledelayedexpansion - enable variable scope referring only to this batch file

    for %% i in (*) to (- starting a FOR loop for the variable "i" which takes the values of individual files "*" from the directory
    if / i not "%% ~ xi" == ". bat" (- if the file extension name "%% ~ xi" is not equal to ".bat", run the commands
    set "f = %% ~ ni" & set "p = %% i" - assign the variable f the value of the file name and assign the variable p the value of the variable i
    if not exist "! f!" md "! f!" - if the directory with the name contained in the variable "f" does not exist, create it
    move "! p!" "! f!")) - move the file named in the variable "p" to the directory named in the variable "f", ending IF commands and ending the FOR loop

    If I have made a mistake, please correct it.
  • #11 16988278
    Pyra19
    Level 10  
    Hello,

    I would like to attach to the topic. I have a very similar problem with sorting documents. The files are in pdf format. named "Skan_20170116153912". I would like to sort the files in the folders YEAR> Month> Day> a file called "scan_20170116153912. More or less I would like the path to look like. I will add that the files arrive every day so this script would be used at least once a week.

    e.g.
    Folder named "2018"
    this folder would contain folders with the names of all months ("JANUARY", "FEBRUARY" etc.)
    and in each of the folders with the name of the month there would be folders with the name of the full date (e.g. 2018-01-01, 2018-01-02 etc.)
    And the corresponding documents would be moved to each dated folder.

    example: scans \ 2018 \ JANUARY \ 02-01-2018 \ scanned_20180102153912.pdf
  • #12 16989360
    dondu
    Moderator on vacation ...
    Pyra19 wrote:
    example: scans \ 2018 \ JANUARY \ 02-01-2018 \ scanned_20180102153912.pdf

    Good advice: Do not use Polish letters in the names of files and folders.
  • ADVERTISEMENT
  • #13 16989374
    rajszym
    Level 21  
    @ Pyra19 : self-study material
    Code: Dos
    Log in, to see the code
  • #14 16990713
    Pyra19
    Level 10  
    Thank you, that's what I meant. :D
  • #15 17081442
    bugaj777nbl
    Level 2  
    Welcome.

    so I would gently like to attach to the topic. Everything above generally suits me :) hula beautifully.
    however, I have a question about one additional variant.
    I need something that will create for me and move files to created folders after the strings contained in it.

    I have something that creates a pdf with the employee's number: from 1 character to 9 inclusive and this is to be the key to creating the file.

    i.e. e.g.

    a0989a__1_kowalski_jan_za_2017.pdf
    a0989a__1_kowalski_jan_za_2016.pdf
    a9121a_21_kowalska_janina_za_2017.pdf
    a9121a_21_kowalska_janina_za_2016.pdf

    e.t.c.

    fixed key / element is here: a0989a__1 and a9121a_21 within these characters I would like directories to be created in sequence:

    a0989a__1 with files: a0989a__1_kowalski_jan_za_2017.pdf, a0989a__1_kowalski_jan_za_2016.pdf
    a9121a_21 with files: a9121a_21_kowalska_janina_za_2017.pdf, a9121a_21_kowalska_janina_za_2016.pdf

    thank you in advance.
  • #16 17081738
    clubs
    Level 38  
    bugaj777nbl wrote:
    I need something that will create and move files to the created folders by the string of characters in it


    Hello
    and where do you see the problem? by rewriting any of the above-mentioned script
  • #17 17082497
    bugaj777nbl
    Level 2  
    Hello.

    thanks for the answer. The problem is that I do not have any basic knowledge about what is written here. I admit that I need it, that it works, and when I sit down for a while, I more or less understand what's going on, but without basic knowledge, I honestly don't know how to move or in any direction.

    So I will be grateful for any tips where you can learn, not to talk about "cash" :)

    greeting, M.

Topic summary

A user sought assistance in creating a batch script to organize smartphone photos into directories based on the date taken, formatted as year.month.day. Initial responses provided a basic script that successfully moved files into newly created folders. Subsequent discussions refined the script to include the desired date format and addressed variations in file naming conventions. Additional users contributed similar requests for organizing files based on different criteria, such as document types and naming patterns. The community provided various script examples and modifications, emphasizing the importance of understanding batch scripting for effective file management.
Summary generated by the language model.
ADVERTISEMENT