# Need help witl a simple batch script

**URL:** <https://boards.straightdope.com/t/need-help-witl-a-simple-batch-script/501987>\
**Category:** In My Humble Opinion\
**Created:** [July 5, 2009, 4:41pm UTC](https://boards.straightdope.com/t/need-help-witl-a-simple-batch-script/501987 "2009-07-05T16:41:52Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MannyL](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@MannyL](https://boards.straightdope.com/u/MannyL)\
**Post date:** [July 5, 2009, 4:41pm UTC](https://boards.straightdope.com/t/need-help-witl-a-simple-batch-script/501987/1 "2009-07-05T16:41:52Z")

</div>

I have a folder lets call it e:\camera which has sub folders 1 through 20 each sub folder has one or more videos taken with the camera and each file name starts with MOVYYY through MOVZZZ for each file in the folder.

I need to move them all into one folder and rename them so there are no duplicate’s. How can I easily do this on XP/Vista/W7

Example  
Folder 1 has MOV001 through MOV004  
Folder 2 has MOV001 through MOV005  
Folder 3 has MOV001 through MOV002

---

<div class="post-metadata">

**Author:** ![Number](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/number/32/242_2.png) [@Number](https://boards.straightdope.com/u/Number)\
**Post date:** [July 5, 2009, 8:53pm UTC](https://boards.straightdope.com/t/need-help-witl-a-simple-batch-script/501987/2 "2009-07-05T20:53:26Z")

</div>

Paste the script below into a text file with a .cmd extension. Customize the value of the **source** variable on line 4 with the location of the folder containing the numbered folders. Customize the value of the **dest** variable on line 5 with the location of the folder to move all of the pictures to.

Running the script will echo commands to move each file to the new directory, prepending the previous path to the name, with dashes substituted for the backslashes. This should prevent there from being any duplicate-apostrophe-s.

Once you have tested it successfully and are sure it will do what you want, remove the word **ECHO** from line 10 to execute the commands.

```auto

@echo off
setlocal enabledelayedexpansion

set source=e:\camera
set dest=c:\videos

for /F "tokens=*" %%G in ('dir "%source%" /A:-D /B /S') do (
 set newname=%%~pnxG
 set newname=!newname:\=-!
 ECHO move "%%G" "%dest%\!newname:~1!"
)

pause

```

---

<div class="post-metadata">

**Author:** ![MannyL](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@MannyL](https://boards.straightdope.com/u/MannyL)\
**Post date:** [July 5, 2009, 9:44pm UTC](https://boards.straightdope.com/t/need-help-witl-a-simple-batch-script/501987/3 "2009-07-05T21:44:46Z")

</div>

> [@Number](#):
>
> Paste the script below into a text file with a .cmd extension. Customize the value of the **source** variable on line 4 with the location of the folder containing the numbered folders. Customize the value of the **dest** variable on line 5 with the location of the folder to move all of the pictures to.
> 
> Running the script will echo commands to move each file to the new directory, prepending the previous path to the name, with dashes substituted for the backslashes. This should prevent there from being any duplicate-apostrophe-s.
> 
> Once you have tested it successfully and are sure it will do what you want, remove the word **ECHO** from line 10 to execute the commands.
> 
> ```auto
> 
> @echo off
> setlocal enabledelayedexpansion
> 
> set source=e:\camera
> set dest=c:\videos
> 
> for /F "tokens=*" %%G in ('dir "%source%" /A:-D /B /S') do (
> set newname=%%~pnxG
> set newname=!newname:\=-!
> ECHO move "%%G" "%dest%\!newname:~1!"
> )
> 
> pause
> 
> ```

Thanks let me try it
