chance
chance

Reputation: 6487

How to copy files into folders with the creation dates as folder names?

I want to copy photos from the memory card into sub-folders on computer file system, each of the sub-folder name is the creation date of the photos.

I need a Windows command or batch file or simple script, by which I can copy the photo files into corresponding sub-folders by providing the source folder and target folder. The sub-folders should be created under the target folder automatically using the creation dates of the photo files from the source folder.

Upvotes: 0

Views: 1423

Answers (1)

Mike Nakis
Mike Nakis

Reputation: 61989

The following batch file:

@echo off
setlocal enabledelayedexpansion
for %%f in (*) do (
    set a=%%~tf
    echo !a:~0,4!-!a:~5,2!-!a:~8,2!
)

will display the date of each file in the current directory in a format suitable for making it part of a filename, assuming that you have set the default date format on your machine to ISO 8601. If not, you will need to change it a little bit, type help set at the command prompt to get information about exactly how that jibberish works. (Keep in mind that I am using !s instead of %s for delayed expansion, but the examples given by the help use %s instead.)

I assume you know how to take it from there.

Upvotes: 1

Related Questions