0

I have a lot of folders and they have the following naming convention:

  • folder1(1924)
  • folder2(2014)
  • folder3(1999)
  • folder4(2001)
  • folder5(1891)

Now I would love to move/find in explorer all the folders where the year (between the ()) is below the year 2000 and above the year 1900

So in the output would be folder1 and folder3.

Is there any script that can do this?

2
  • Is it year part of the directory name? Jun 8, 2015 at 8:31
  • Yea every folder has the year in the name
    – Kiwi
    Jun 8, 2015 at 8:35

2 Answers 2

2

If all those folders are under C:\Source folder then run the following batch file from C:\Source folder itself:

@echo off
set dest=D:\Target folder
for /f "tokens=1,2 delims=()" %%d in ('dir /ad /b') do (
    if %%e gtr 1900 (
        if %%e lss 2000 (
            if not exist "%dest%\%%d(%%e)\" md "%dest%\%%d(%%e)"
            robocopy "%%d(%%e)" "%dest%\%%d(%%e)" /e /is /move
        )
    )
)
2
  • It gives the follwoing error ` ERROR 2 (0x00000002) Accessing Source Directory `
    – Kiwi
    Jun 8, 2015 at 10:24
  • Found out why, there are some things behind the year aswell ;) fixing that
    – Kiwi
    Jun 8, 2015 at 10:53
0

Here is one sample way to do this (assuming all directories are on one level)

find . -type d -name "fold*" -maxdepth 1|awk -F'[()]'  '{if ($2 > 1900 && $2 < 2000) print $0}'

If you want to execute it under Windows OS the samples way is to use some cygwin environment (also mobaxterm work fine) and to run it in terminal. Unfortunately my Windows skills are very modest and I can't rewrite it for native cmd script

1
  • You might want to include instructions on how the OP can run this in Windows.
    – Karan
    Jun 8, 2015 at 9:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .