2

I am a little green to this part of batch scripting, but what I am trying to do is a append a bunch of folder names and increment by 1 whilst respecting the time stamp i.e newest folder first, oldest folder last.

I have looked at other scripts with no avail.

Before

Folder 1
Folder 2
Folder 3
Folder 4
Folder 5
Folder 6

After

Folder 1 - Part 001          - Time stamp 1/1/2014 - 18:55:20
Folder 4 - Part 002          - Time stamp 1/1/2014 - 18:55:24
Folder 3 - Part 003          - Time stamp 1/1/2014 - 18:56:28
Folder 6 - Part 004          - Time stamp 1/1/2014 - 18:58:24
Folder 5 - Part 005          - Time stamp 1/1/2014 - 18:59:20
Folder 43 - Part 006          - Time stamp 1/1/2014 - 18:59:59

Extra function

Is there a way to do all the above but skip all folders that contain - GROUP VIDEO at the end of it. (I am not sure if I should create a new post or not?)

Arthor
  • 666
  • 2
  • 13
  • 40

1 Answers1

2

Test this:

@echo off
setlocal enabledelayedexpansion
set num=0
for /f "delims=" %%a in ('dir /b /ad /o-d ^|find /i /v "GROUP VIDEO" ') do (
set /a num+=1
set name=000!num!
set name=!name:~-3!
ren "%%a" "%%a - Part !name!"
)
pause
foxidrive
  • 40,353
  • 10
  • 53
  • 68
  • Wow, that was quick! Testing now. Thank you – Arthor Jul 16 '14 at 17:04
  • If I wanted specify the folder location where to do the operations, would it be `cd\` then `cd c:\test\test`. Tried it but no joy. Thanks – Arthor Jul 16 '14 at 17:21
  • 1
    After line 3 add `cd /d "c:\test\test"` – foxidrive Jul 17 '14 at 01:23
  • Is there a way to get the above code to skip any folder containing the phrase `GROUP VIDEO`. Thank you, PS. If you want me to create a new thread please let me know. – Arthor Jul 18 '14 at 19:06
  • Just out of curiosity, would this be correct `('dir /b /ad /o-d ^|find /i /v "GROUP VIDEO" ^|find /i /v "GROUP AUDIO" ')` To have multiple expressions? – Arthor Jul 19 '14 at 19:13
  • 1
    Yes. You could use just one expression too in your case to filter them both on one pass. This would be faster but for a small number of folders you couldn't tell. `^|find /i /v " - GROUP"` NOTE too that the `- GROUP` is case insensitive with the `/i` switch. – foxidrive Jul 19 '14 at 19:29
  • Ok, so this would be correct? `('dir /b /ad /o-d ^|find /i /v "GROUP VIDEO" ^|find /i /v "SERVER STATS" ')` – Arthor Jul 19 '14 at 19:37