I am attempting to clean up a multimedia folder for multiple users. Currently the folders are like this:
c:\multimedia\user1\music1
c:\multimedia\user1\music2
c:\multimedia\user1\music3
c:\multimedia\user2\music1
c:\multimedia\user2\music2
c:\multimedia\user2\music3
I have about 10,000 users. I would like to run a batch file that will clean this up. I would like to merge all music folders under each user.
I do not know how to do this, but the output should look something like this:
c:\multimedia\user1\music
c:\multimedia\user2\music
Batch Help - Merging Folders
Moderator: DosItHelp
Re: Batch Help - Merging Folders
This is untested.
Copy \user1\music1/2/3 to c:\test\multimedia\ and run this to see if it works as you expect it to.
Any files with the same name in music1/2/3/4 etc will be overwritten.
Copy \user1\music1/2/3 to c:\test\multimedia\ and run this to see if it works as you expect it to.
Any files with the same name in music1/2/3/4 etc will be overwritten.
Code: Select all
@echo off
set d=c:\test\multimedia
for /f "delims=" %%a in ('dir "%d%" /b /ad') do (
pushd "%d%\%%a"
md tempmusic
for /f "delims=" %%b in ('dir music* /b /ad') do (
move /y "%%b\*.*" tempmusic
rd "%%b"
)
ren tempmusic Music
popd
)
-
- Posts: 4
- Joined: 02 Mar 2012 09:49
Re: Batch Help - Merging Folders
But what about user2 and the other 10k? I need to keep the folder structures the same... multimedia\user1\music , multimedia\user2\music... etc... I have over 10,000 users.
Not finding much when googling. Kindof discouraged. I don't know what I need, but maybe some type of variable in the filepath that could link the users, ie:
copy "c:\multimedia\*VARIABLE*\music1" "c:\multimedia\*VARIABLE*\music"
copy "c:\multimedia\*VARIABLE*\music2" "c:\multimedia\*VARIABLE*\music"
copy "c:\multimedia\*VARIABLE*\music3" "c:\multimedia\*VARIABLE*\music"
delete "c:\multimedia\*VARIABLE*\music1"
delete "c:\multimedia\*VARIABLE*\music2"
delete "c:\multimedia\*VARIABLE*\music3"
where the *VARIABLE* is user1, user2, user3, user4, etc. The actual usernames in my folder structures are like this: {5D5D23C2-A2D8-49D4-802C-641A1592B158}. With each user having different letter and number combos.
Not finding much when googling. Kindof discouraged. I don't know what I need, but maybe some type of variable in the filepath that could link the users, ie:
copy "c:\multimedia\*VARIABLE*\music1" "c:\multimedia\*VARIABLE*\music"
copy "c:\multimedia\*VARIABLE*\music2" "c:\multimedia\*VARIABLE*\music"
copy "c:\multimedia\*VARIABLE*\music3" "c:\multimedia\*VARIABLE*\music"
delete "c:\multimedia\*VARIABLE*\music1"
delete "c:\multimedia\*VARIABLE*\music2"
delete "c:\multimedia\*VARIABLE*\music3"
where the *VARIABLE* is user1, user2, user3, user4, etc. The actual usernames in my folder structures are like this: {5D5D23C2-A2D8-49D4-802C-641A1592B158}. With each user having different letter and number combos.
Re: Batch Help - Merging Folders
Yeah, it's designed to do that. You need to test it though, unless you want to backup the 10,000 users and test it on the lot. 

-
- Posts: 4
- Joined: 02 Mar 2012 09:49
Re: Batch Help - Merging Folders
Awesome! Tested and working. Thank you!
Follow up question:
If I wanted to rename the files in a particular folder to the date modified in this format: 2012.03.03.pdf is this possible?
Thanks again!
Follow up question:
If I wanted to rename the files in a particular folder to the date modified in this format: 2012.03.03.pdf is this possible?
Thanks again!
Re: Batch Help - Merging Folders
You do realise that with that name format that you can only have one file of each filetype - because they would have the same name.
You didn't give any indication of folder but this code below should work for the folder it is in.
Change the last line to this if you want this format "orginal filename_2012.03.04.ext"
) do ren "%%a" "%%~na_%timestamp%%%~xa"
You didn't give any indication of folder but this code below should work for the folder it is in.
Code: Select all
@echo off
setlocal EnableExtensions
:: Date and time routines by Ritchie Lawrence
:: Windows NT4 and above
:begin
(set today=%date%)
set t=2&if "%date%z" LSS "A" set t=1
for /f "skip=1 tokens=2-4 delims=(-)" %%a in ('echo/^|date') do (
for /f "tokens=%t%-4 delims=.-/ " %%d in ('date/t') do (
set %%a=%%d&set %%b=%%e&set %%c=%%f))
(set yy=%yy%&set mm=%mm%&set dd=%dd%)
for /f "tokens=5-8 delims=:. " %%a in ('echo/^|time') do (
set hh=%%a&set nn=%%b&set ss=%%c&set cs=%%d)
if 1%hh% LSS 20 set hh=0%hh%
(set hh=%hh%&set nn=%nn%&set ss=%ss%&set tt=%cs%)
if not "%date%"=="%today%" goto :begin
:: The following lines set and echo the timestamp variable
set timestamp=%yy%-%mm%-%dd%_%hh%.%nn%.%ss%
set timestamp=%yy%.%mm%.%dd%
echo timestamp=%timestamp%
for /f "delims=" %%a in (
'dir *.* /b /a-d ^|find /v "%~nx0"'
) do ren "%%a" "%timestamp%%%~xa"
Change the last line to this if you want this format "orginal filename_2012.03.04.ext"
) do ren "%%a" "%%~na_%timestamp%%%~xa"
-
- Posts: 4
- Joined: 02 Mar 2012 09:49
Re: Batch Help - Merging Folders
Thanks for the reply. I reviewed this and it looks like it will be putting a timestamp of today's date. I am looking to rename the files to the "Date Modified".
Thanks!
Thanks!
Re: Batch Help - Merging Folders
Oh, ok.
Try this - I had it squirreled away from a previous request.
Remove the 'echo' if it looks right, to actually enable the rename.
The order of %%c %%b %%a is probably regional and may need to be adjusted.
Try this - I had it squirreled away from a previous request.
Remove the 'echo' if it looks right, to actually enable the rename.
The order of %%c %%b %%a is probably regional and may need to be adjusted.
@echo off
setlocal
for /f "delims=" %%a in ('dir /a:-d /b') do call :ren "%%a"
pause
goto :EOF
:ren
for /f "tokens=1-5 delims=/-: " %%a in ("%~t1") do set datetime=%%c.%%b.%%a
echo ren %1 "%datetime%%~x1"