Solved

Copy folder and files with folder structure IF filetype is present

Posted on 2011-09-29
98
610 Views
Last Modified: 2012-06-27
Hi all!

I need to copy all folders that contain *.flac with their current folder structure, and I also need to be able to either copy all files & folders in that folder with exceptions or just chose what file type & folder to copy if *.flac is present in that folder.

Basicly:

Search my music folder
copy ALL folders that contain *.flac wtih their current folder structure.
I must be able to include and or exclude file types and folders during this copy procedure from those folders that contain *.flac.

Ex: If *.flac is present ie D:/Music/Rippet/Some Artist/Some Album/Coolsong.flac, then I want
D:/Music/Rippet/Some Artist/Some Album/text.txt
D:/Music/Rippet/Some Artist/Some Album/album.jpg
D:/Music/Rippet/Some Artist/Some Album/cuesheet.cue
and all sub folders to be copied along during this copy to f.ex
E:/New Folder/Rippet/Some Artist/Some Album/Coolsong.flac
E:/New Folder/Rippet/Some Artist/Some Album/text.txt
etc etc
!!!But, I don't want f.ex
D:/Music/Rippet/Some Artist/Some Album/coolsong.mp3
D:/Music/Rippet/Some Artist/Some Album/coolsong.aac
D:/Music/Rippet/Some Artist/Some Album/coolsong.wav
etc
I need these and other spesific file types to be excluded during the copy!!!

What I DON'T want to do under any circumstances to name files or folders with their names during this procedure, as this would take way to long time.

Atm their about 46000 files and folders to search through, but shortly this will increase 3-4 times.

Current OS is Win 7.

Sry about my english, it's a little rusty.

I dont mind using commands IF their isn't a program that can make this happen. Free or not doesnt matter to me.

Cheers
TO
0
Comment
Question by:TheOnly4u
  • 45
  • 19
  • 18
  • +4
98 Comments
 
LVL 78

Expert Comment

by:David Johnson, CD, MVP
ID: 36829364
easier just to find folders with .flac file and then copy EVERYTHING then delete what you don't want
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 36830793
My question would be can you do it either one way or the other.  By that I mean, could you control wich files by either just specifying the types to include (FLAC, JPG, TXT, CUE), or could you say to copy all but certain extensions (MP2, WAV, AAC).

If one or the other would work (but not both, then this shouldn't be hard to do. If on the other hand there are files with the same type that some of those need to be copied, and some skipped, then that would be a bit more involved.

~bp
0
 

Author Comment

by:TheOnly4u
ID: 36830973
Easier maybe, bot takes longer time, time is money.
0
 

Author Comment

by:TheOnly4u
ID: 36832472
Well as long as the result is the same, billprew, you can say that I can do it both ways. The point being one operation/command and that the "non wanted" file types dont get copied.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 36832978
Also, is it true that there will be folders that don't have a FLAC file in them, and those folders need to skipped completely, even if they contained say "album.jpg"?

~bp
0
 

Author Comment

by:TheOnly4u
ID: 36833554
And Important, Folder structure must be intact. And ALL sub folder must always be copied even if empty.
0
 

Author Comment

by:TheOnly4u
ID: 36833734
sry.. sub folders in a folder that contains *.flac
0
 

Author Comment

by:TheOnly4u
ID: 36834514
The point is to get ALL folders with folder structure that contains flac files. ALL files and sub folders minus a few excluded file types must be copied.
0
 

Author Comment

by:TheOnly4u
ID: 36835320
basicly copy everything in a folder if it contains a flac file, execpt other music file types like mp3 wav etc
0
 

Author Comment

by:TheOnly4u
ID: 36836607
yes billprew if a folder or its subfolders doesnt contain a flac file, then skip it.
0
 

Author Comment

by:TheOnly4u
ID: 36838412
but as I said the root folder and its subfolders should only contain folder structure all the way down to the subfolder that actually contains a flac file.
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 36840099
Okay, I've got an approach that might work, but will take a bit of time to put together and test.  Getting late in the day where I am, so will be tomorrow before I can deliver something for you to try.

Would it be possible for you to do one or more TREE /F commands on parts of the folder structure showing folders that would be copied, and some that wouldn't?  I just want to be sure I fully understand.

~bp
0
 

Author Comment

by:TheOnly4u
ID: 36854351
Hi billprew here is a text file with TREE /F example folder and files. I've also explained a little in the text file. folder.txt

remember that atm there are about 50k files and folders but this will increase to ovet 180k in a few months.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36890660
My logic here was along these lines, though I dn't really have time to finish this maybe it will help along the way?
I am assuming the "source" directory will sit there and get updated and that the "destination" directory may not be empty?
xcopy /d /s (just changes) of all .FLAC files from source to destination.  Capture list of files copied to a file.
run down this list of FLAC files copied.  For each change of directory name:
   xcopy /d *.jpg *.cue, *.log etc. using loop:
So roughly like this.
Where I get stuck for now is in the bit "replace source path with dest", otherwise I think the logic is good?

What would be easy, for instance, is if the paths were

d:\music\
e:\music\

because then the line:

REM replace source path with dest
    set destdir=!sourcedir:%source%=%dest%!

Could be
    set destdir=E:%%~pA


@echo off
setlocal enabledelayedexpansion

set source=c:\source
set dest=c:\dest
set include=jpg,cue,log
set logfile="%source%\log.txt"
set copied="%source%\copied.txt"


rem xcopy /y /d /s "%source%\*.flac" "%dest%" > %copied% 2>%logfile%
  if errorlevel 1 echo There was an error %errorlevel% copying >%logfile%


set sourcedir=
for /f "tokens=*" %%A in ('type %copied% ^| find /v "File(s) copied"') do (

  REM Check if the directory to copy is different to the last one
  if NOT "%%~dpA"=="!sourcedir!" (

    REM Get the directory and drive only
    set sourcedir=%%~dpA

    REM replace source path with dest
    set destdir=!sourcedir:%source%=%dest%!

    echo Need to copy other files from dir %%~dpA

    REM work down extensions in include variable and copy
    for %%T in (%include%) do echo xcopy /d "%%~dpA*.%%T" "!destdir!"
  )
)

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36890666
(sorry the echo in front of xcopy was during my testing so as to use the same "copied.txt" file.

0
 

Author Comment

by:TheOnly4u
ID: 36890860
I'll try this when I get home...
Your right, the source folder i lave and forever growing. I make changes and convert etc in there. the destination folder will always be the same and therefor after the first command/copy run it contain files.

But there will always be new folder/subfolders to update or add.
0
 

Author Comment

by:TheOnly4u
ID: 36890865
It should say "live"
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36890934
In which case the xcopy /d will only cope new so it should work well I guess.

Oh BTW when copying from the "code" section sometimes you get extra spaces at the end of the line.  If so pls remove them or use the atatched file.
@echo off
setlocal enabledelayedexpansion

set source=d:\music
set dest=e:\music
REM Change "E:" in the line "set destdir=" to the destination drive letter
REM only works as long as the source path and dest. path are the same except drive letter.
REM Otherwise will have to do some more clever processing!

set include=jpg,cue,log
set logfile="%source%\log.txt"
set copied="%source%\copied.txt"


rem xcopy /y /d /s "%source%\*.flac" "%dest%" > %copied% 2>%logfile%
  if errorlevel 1 echo There was an error %errorlevel% copying >%logfile%


set sourcedir=
for /f "tokens=*" %%A in ('type %copied% ^| find /v "File(s) copied"') do (

  REM Check if the directory to copy is different to the last one
  if NOT "%%~dpA"=="!sourcedir!" (

    REM Get the directory and drive only
    set sourcedir=%%~dpA

    REM replace source path with dest
    set destdir=E:%%~dpA

    echo Need to copy other files from dir %%~dpA

    REM work down extensions in include variable and copy
    for %%T in (%include%) do echo xcopy /d "%%~dpA*.%%T" "!destdir!"
  )
)

Open in new window

copyme.cmd
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 36891158
Okay, I am getting the feel for this.  One question though, you mention you want to copy empty folders, what's the need there?  I *think* you might be able to do the whole thing with a single robocopy command if it weren't for that requirement.

~bp
0
 

Author Comment

by:TheOnly4u
ID: 36891175
The empty folder is not a deal breaker IF it's a subfolder to the folder that contains the flac...I'm trying the edited command now. Added all the files I want transfered. It will take a while. I'll post when it's finished.
0
 

Author Comment

by:TheOnly4u
ID: 36891249
well I've edited the file you gave with the right destination an source location and added all the file types to copy if there is a flac file(s) present. Can you check if it's okay or if more needs to be done.
copymeedited.cmd
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36891255
Hmm, thought about Robocopy Bill but couldn't work out a way of only copying the related files from the same dir. only if there were FLAC files in there?

As to the empty folders, if these are to be any folders under a directory with FLAC files in then could do another check within the loop ... or run an xcopy, e.g.

i.e amend this bit:


    for %%T in (%include%) do echo xcopy /d "%%~dpA*.%%T" "!destdir!"  


to add another line:


    REM Copy any subdirs of a directory with flac files in (empty or not)
    xcopy /e /d "%%~dpA*.OnlyDirs" "!destdir!"

Interested to see how you'd do this in Robocopy Bill!
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 36891286
Okay, I am going to play around with this further, set up some test folders, etc.  But I've got some real work to take care of for a bit, so it may take me some time to get something working.  If you need it sooner than that I'll understand if you have to move on, but just wanted to let you know where I stand.

~bp
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36891291
That looks good to me.  If you want it to try the xcopy without doing anything add /L to each of the xcopy commands.  This will just SHOW what would copy without actually doing it.
0
 

Author Comment

by:TheOnly4u
ID: 36891419
I got time.. to wait for a working solution. Thx for helping.

TO
0
 
LVL 21

Expert Comment

by:yo_bee
ID: 36891475
Have looked into Robocopy?

It is part of Vista,W7 and 2008 .  It also can be downloaded from Microsoft if you are running xp or 2003

Robocoby "source" "dest" /e /xo /if *.flac /w:1 /r:1 /log:"log name".txt /NP /tee

This should do the trick. If you want to add additional files just put a space after .flac and add *.mov. Etc.
0
 

Author Comment

by:TheOnly4u
ID: 36891996
yo bbe hi...

I only want to copy that folder IF there is a flac file present with the folder structure intact,.So far so easy, but if I add *.txt *.jpg like you say, will it not copy ALL folders with folder structure that contains *.txt *.jpg?

I have over 1k folder that dont have flac but they do hav txt and jpg.

Correct me if Im wrong?
0
 

Author Comment

by:TheOnly4u
ID: 36892126
I can see that this one is hard so I've increased the point value to max...

cheers
TO
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36892262
Did you try my batch file?  In my own test structure it did as you ask afai can tell.
0
 
LVL 21

Expert Comment

by:yo_bee
ID: 36892272
That is what RC does.
/E = all sub directorys
/IF = include Files that match (wildcards can be used)
0
 
LVL 21

Expert Comment

by:yo_bee
ID: 36892285
It will copy files that match
So if you just want *.FLAC then if the folder has a single file with .FLAC that file and folder structure is copied.
If you add *.FLAC *.TXT *.JPG  then the same applies.  If one folder has *.FLAC that file and folder are copied, but if the Folder has a txt file then it will copy that one and so on and so on.
0
 

Author Comment

by:TheOnly4u
ID: 36892290
I think you need to send me a file where source is "F:\Musikk" and dest. is "D:\Musikk

Cheers
TO
0
 

Author Comment

by:TheOnly4u
ID: 36893489
Well I've tried but no files are copied or log files generated, get small error in cmd like
"Need to copy other files from dir %%~dpA"
"%%A was not expected" in Norwegian
etc..
0
 
LVL 21

Expert Comment

by:yo_bee
ID: 36893542
Try robocopy and see if that looks.  You will like it.
0
 

Author Comment

by:TheOnly4u
ID: 36893576
Yo bee we just established that I can do anything that RC can do with most advanced fileprograms. Using RC will give me 5-6 hours of looking on folders with just txt jpg cue etc and then deleting them...and then do the same thing again every time I run RC...no thx.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36893607
i will check if something has lost in the copy/paste, it worked on my own set of mock data.  kids bath and bed time so might get a chance in 5-6 hrs!!

Robocopy will copy the flac files but cant see how it will then be copying your other filtered files from the rest of the dir.

Does xcopy respond file(s) copied btw or some other localised words?

0
 
LVL 21

Expert Comment

by:yo_bee
ID: 36893985
I am sorry. I think I misunderstood the question.
I thought that the Asker was looking to just copy FLAC files not search for FLAC and if there is a FLAC file copy the entir Directory + Sub structure.


0
 
LVL 1

Expert Comment

by:jjthomas3
ID: 36894470
You say you are running Windows 7. That having been said Batch files are not the way to go. Look to PowerShell.

This PowerShell script will do exactly what you want, but you need to change all the paths in the script to match your paths.
 
# Get a list of folder that cantain *.flac Files
$myFLACFolders = get-childitem D:\MyMusicFolder\Music -recurse -filter "*.flac" | %{$_.DirectoryName} | Get-Unique 

# Create a small array of files you want excluded.
$myExcludedFiles = "*.mp3", "*.wma", "*.acc", "*.ogg"

# Copy the folders, continue on errors and warnings, log operation to file
foreach ($folder in $myFLACFolders){
	Copy-Item -Path $folder -Destination "E:\MyNewMusicFolder\" -Recurse -Exclude $myExcludedFiles -WarningAction Continue -ErrorAction Continue -Force -Verbose | Out-File "e:\MyNewMusicFolder\copyOperation.log" -Append
}

Open in new window

0
 
LVL 1

Expert Comment

by:jjthomas3
ID: 36894502
On a side note for speed....
  I would not advise writing the log file to the same drive as the file copy operation if you want it to go much faster. It can go much much faster if you drop logging and -verbose completely as such:

 
# Get a list of folder that cantain *.flac Files
$myFLACFolders = get-childitem F:\Entertainment\Music -recurse -filter "*.flac" | %{$_.DirectoryName} | Get-Unique 

# Create a small array of files you want excluded.
$myExcludedFiles = "*.mp3", "*.wma", "*.acc", "*.ogg"

# Copy the folders, continue on errors and warnings, log operation to file
foreach ($folder in $myFLACFolders){
	Copy-Item -Path $folder -Destination "E:\MyNewMusicFolder\" -Recurse -Exclude $myExcludedFiles -WarningAction Continue -ErrorAction Continue -Force
}

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36894950
Tried my batch again if youdo try that way... can see few bits in your edited file did not work quite as expected.  I have edited those and added few extra checks:

@echo off
setlocal enabledelayedexpansion

set source=f:\Musikk
set dest=d:\Musikk

REM Change "E:" in the line "set destdir=" to the destination drive letter
REM only works as long as the source path and dest. path are the same except drive letter.
REM Otherwise will have to do some more clever processing!

set include=jpg,cue,log,txt,png,gif
set logfile="%source%\log.txt"
set copied="%source%\copied.txt"
set FilesCopied="File(s) copied"

echo Looking for FLAC files to copy
xcopy /y /d /s "%source%\*.flac" "%dest%" > %copied% 2>%logfile%
  if errorlevel 1 echo There was an error %errorlevel% copying >>%logfile%

set sourcedir=
for /f "tokens=*" %%A in ('type "%copied%" ^| find /v %FilesCopied%') do (

  REM Check if the directory to copy is different to the last one
  if NOT "%%~dpA"=="!sourcedir!" (

    REM Get the directory and drive only
    set sourcedir=%%~dpA

    REM replace source path with dest
    set destdir=E:%%~pA

    echo Directory %%~dpA being copied
    echo Directory %%~dpA being copied >>%logfile%

    REM work down extensions in include variable and copy
    for %%T in (%include%) do (
      if exist "%%~dpA*.%%T" (
        echo Found .%%T files to copy
        xcopy /d "%%~dpA*.%%T" "!destdir!" | FIND /V %FilesCopied% >>%LOGFILE% 2>&1
      )
    )
    REM Copy any subdirs of a directory with flac files in (empty or not)
    dir /ad /b "%%~dpA" >>%logfile%
    xcopy /e /d "%%~dpA*.OnlyDirs" "!destdir!" 2>&1
  )
)
notepad %logfile%


Log file:

Directory C:\temp\music\a\ being copied 
C:\temp\music\a\test.jpg
C:\temp\music\a\test.cue
y
z
Directory C:\temp\music\c\ being copied 
C:\temp\music\c\test.jpg

Open in new window

Source dir:

Folder PATH listing for volume W2K BOOT
Volume serial number is 0006FE80 30C9:7BBA
C:.
|   copied.txt
|   log.txt
|   tree.txt
|   
+---a
|   |   test.cue
|   |   test.jpg
|   |   test.xxx
|   |   test.yyy
|   |   test1.flac
|   |   test2.flac
|   |   test3.flac
|   |   test4.flac
|   |   test5.flac
|   |   
|   +---y
|   \---z
|           xxxx.fsd
|           
+---b
|       test1.mp3
|       test2.mp3
|       test3.mp3
|       test4.mp3
|       test5.mp3
|       
\---c
        test.jpg
        test.mp3
        test1.flac
        test2.flac
        test3.flac
        test4.flac
        test5.flac

Open in new window

Destination path

Folder PATH listing for volume VMWARE
Volume serial number is 0006FE80 7C77:A3A6
E:.
|   tree.txt
|   
+---a
|   |   test.cue
|   |   test.jpg
|   |   test1.flac
|   |   test2.flac
|   |   test3.flac
|   |   test4.flac
|   |   test5.flac
|   |   
|   +---y
|   \---z
\---c
        test.jpg
        test1.flac
        test2.flac
        test3.flac
        test4.flac
        test5.flac

Open in new window

0
 

Author Comment

by:TheOnly4u
ID: 36896333
Hi dragon-it!

It's almost working alright, but it's not copying the subfolders with content...it's just copies the subfolder without content IF it dont conatins a flac. See example.

 
F:.
¦   Phil Collins - In the air tonight (1).mp3
¦
+---Going Back
¦       00. Phil Collins - Going Back.nfo
¦       01 - Girl (Why You Wanna Make Me Blue).flac
¦       02 - (Love Is Like A) Heatwave.flac
¦       03 - Uptight (Everything's Alright).flac
¦       04 - Some Of Your Lovin'.flac
¦       05 - In My Lonely Room.flac
¦       06 - Take Me In Your Arms (Rock Me For A Littl
¦       07 - Blame It On The Sun.flac
¦       08 - Papa Was A Rolling Stone.flac
¦       09 - Never Dreamed You'd Leave In Summer.flac
¦       10 - Standing In The Shadows Of Love.flac
¦       11 - Do I Love You.flac
¦       12 - Jimmy Mack.flac
¦       13 - Something About You.flac
¦       14 - Love Is Here And Now You're Gone.flac
¦       15 - Loving You Is Sweeter Than Ever.flac
¦       16 - Going To A Go-Go.flac
¦       17 - Talkin About My Baby.flac
¦       18 - Going Back.flac
¦       Going Back.cue
¦
+---Hits [FLAC]
¦   ¦   01 - Another Day in Paradise.flac
¦   ¦   02 - True Colors.flac
¦   ¦   03 - Easy Lover.flac
¦   ¦   04 - You Can't Hurry Love.flac
¦   ¦   05 - Two Hearts.flac
¦   ¦   06 - I Wish It Would Rain Down.flac
¦   ¦   07 - Against All Odds.flac
¦   ¦   08 - Something Happened on the Way to Heaven.f
¦   ¦   09 - Separate Lives.flac
¦   ¦   10 - Both Sides of the Story.flac
¦   ¦   11 - One More Night.flac
¦   ¦   12 - Sussudio.flac
¦   ¦   13 - Dance into the Light.flac
¦   ¦   14 - A Groovy Kind of Love.flac
¦   ¦   15 - In the Air Tonight.flac
¦   ¦   16 - Take Me Home.flac
¦   ¦   nfo.txt
¦   ¦   Phil Collins - Hits (1998).cue
¦   ¦   Phil Collins - Hits (1998).log
¦   ¦   Phil Collins - Hits (1998).m3u
¦   ¦
¦   +---Covers
¦           Phil Collins - Hits-back.jpg
¦           Phil Collins - Hits-cd.jpg
¦           Phil Collins - Hits-front.jpg
¦
+---Testify
        01 - Wake Up Call.mp3
        02 - Come With Me.mp3
        03 - Testify.mp3
        04 - Dont Get Me Started.mp3
        05 - Swing Low.mp3
        06 - It's Not Too Late.mp3
        07 - This Love This Heart.mp3
        08 - Driving Me Crazy.mp3
        09 - The Least You Can Do.mp3
        10 - Cant Stop Loving You.mp3
        11 - Thru My Eyes.mp3
        12 - You Touch My Heart.mp3

Open in new window

D:.
+---Going Back
¦       01 - Girl (Why You Wanna Make Me Blue).flac
¦       02 - (Love Is Like A) Heatwave.flac
¦       03 - Uptight (Everything's Alright).flac
¦       04 - Some Of Your Lovin'.flac
¦       05 - In My Lonely Room.flac
¦       06 - Take Me In Your Arms (Rock Me For A Little While).flac
¦       07 - Blame It On The Sun.flac
¦       08 - Papa Was A Rolling Stone.flac
¦       09 - Never Dreamed You'd Leave In Summer.flac
¦       10 - Standing In The Shadows Of Love.flac
¦       11 - Do I Love You.flac
¦       12 - Jimmy Mack.flac
¦       13 - Something About You.flac
¦       14 - Love Is Here And Now You're Gone.flac
¦       15 - Loving You Is Sweeter Than Ever.flac
¦       16 - Going To A Go-Go.flac
¦       17 - Talkin About My Baby.flac
¦       18 - Going Back.flac
¦       Going Back.cue
¦
+---Hits [FLAC]
    ¦   01 - Another Day in Paradise.flac
    ¦   02 - True Colors.flac
    ¦   03 - Easy Lover.flac
    ¦   04 - You Can't Hurry Love.flac
    ¦   05 - Two Hearts.flac
    ¦   06 - I Wish It Would Rain Down.flac
    ¦   07 - Against All Odds.flac
    ¦   08 - Something Happened on the Way to Heaven.flac
    ¦   09 - Separate Lives.flac
    ¦   10 - Both Sides of the Story.flac
    ¦   11 - One More Night.flac
    ¦   12 - Sussudio.flac
    ¦   13 - Dance into the Light.flac
    ¦   14 - A Groovy Kind of Love.flac
    ¦   15 - In the Air Tonight.flac
    ¦   16 - Take Me Home.flac
    ¦   nfo.txt
    ¦   Phil Collins - Hits (1998).cue
    ¦   Phil Collins - Hits (1998).log
    ¦
    +---Covers


As you see the subfolder is empty

Open in new window


As you see the the Cover subfolder that has the cover images are copied without the cover images.
0
 

Author Comment

by:TheOnly4u
ID: 36896343
As I said before the empty folders aren't a deal breaker for me, but I have to have ALL subfolders containing the support files for my flac music. This being jpg,cue,log,txt,png,gif at the moment.
0
 

Author Comment

by:TheOnly4u
ID: 36896405
jjthomas3 Hi!

I'm testing your PS now with your scriptm but is there a way to use include istead of exclude?

The file type that is to be excluded are wast, unknown and always changing and or increasing. The number of files to be included are always known and few.
0
 

Author Comment

by:TheOnly4u
ID: 36896428
jjthomas and dragon-it!

Is there a way to change file to copied if present (flac), to ex mp3 based on "Bit Rate"? That is I want the 190-320 bit mp3s as an example.

And the 2 solutions you have provided, will it skip files already present in destination the next time I run the command/script?

I know, I know...I'm being difficult, but it's the time saving that drives me to as when I have competent to ask... :)
0
 

Author Comment

by:TheOnly4u
ID: 36896525
I've tried the PS script and it fails on so many levels I dont know where to start. I suggest you read all the posts in here to see what it is that I need it's explained many times. And test the script before posting it!.
Thx for trying to help thow.
0
 

Author Comment

by:TheOnly4u
ID: 36896597
dragon-it!

If there is no way to use include with the options I need the I can live with exclude filetypes...I dont want to, but it's doable.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36896810
<<Is there a way to change file to copied if present (flac), to ex mp3 based on "Bit Rate"? That is I want the 190-320 bit mp3s as an example.>>

No frankly!

As to the folders only copying empty dirs I thought that was what you wanted, obviouly misunderstood.

This bit at the end

    REM Copy any subdirs of a directory with flac files in (empty or not)
    dir /ad /b "%%~dpA" >>%logfile%
    xcopy /e /d "%%~dpA*.OnlyDirs" "!destdir!" 2>&1

does what it says and copies any subdirs as empty.

So if you want ALL subdirs of a Flac directory then?

If so change those three lines to:

    REM Copy any subdirs of a directory with flac files in (empty or not)
    dir /ad /b "%%~dpA" >>%logfile%
    xcopy /e /d "%%~dpA*.*" "!destdir!" 2>&1


That will copy ALL file types from those subdirs of a directory with FLAC in AND any subdirs of those.

Is that what you want?

My batch file will only copy FLAC files that have changed.  It then looks in those directories only to look for the other files and subdirs to cpy.

Steve
0
 

Author Comment

by:TheOnly4u
ID: 36896883
sorry if I'm confusing you guys..

The include you made with "set include=jpg,cue,log,txt,png,gif", should also be made to apply for

 REM Copy any subdirs of a directory with flac files in (empty or not)
    dir /ad /b "%%~dpA" >>%logfile%
    xcopy /e /d "%%~dpA*.*" "!destdir!" 2>&1

The only filetypes I want is flac, and the flac support files jpg,cue,log,txt,png,gif when they are in the folders(and their subfolders) that contains flac. I don't know how to explain it otherwise.

Let's say F:\Musikk\Eagles\ contain this:
F:\Musikk\Eagles\song1.flac
F:\Musikk\Eagles\song2.flac
F:\Musikk\Eagles\song1.mp3
F:\Musikk\Eagles\song2.mp3
F:\Musikk\Eagles\text.txt
F:\Musikk\Eagles\cover.jpg
F:\Musikk\Eagles\subFolder\coverart.jpg
F:\Musikk\Eagles\subFolder\coverart2.jpg
F:\Musikk\Eagles\subFolder\coverart3.gif
F:\Musikk\Eagles\subFolder\song1.wav

What I want to end up with at D:\Musikk is:
D:\Musikk\Eagles\song1.flac
D:\Musikk\Eagles\song2.flac
D:\Musikk\Eagles\text.txt
D:\Musikk\Eagles\cover.jpg
D:\Musikk\Eagles\subFolder\coverart.jpg
D:\Musikk\Eagles\subFolder\coverart2.jpg
D:\Musikk\Eagles\subFolder\coverart3.gif

That is just an example and not all files I need included/excluded.

Cheers
TO
0
 

Author Comment

by:TheOnly4u
ID: 36896892
The following files should not be copied:

F:\Musikk\Eagles\song1.mp3
F:\Musikk\Eagles\song2.mp3
F:\Musikk\Eagles\subFolder\song1.wav
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 51

Expert Comment

by:Bill Prew
ID: 36896942
I've been reading along and trying different approaches, but there isn't a simple clean one from what I have found.

That being said, I think I would ask "what are you trying to do?" at this point.  It doesn't feel like you are coming at this right to me, since you now want to skip over previously processed files / folders, etc.  I would like to better understand the "process" that you envision, and what you are trying to accomplish.  Why are you copying the files at all, and why just the FLAC files.  What happens if FLAC files are deleted from the source location after you copy the files / folders.  Where do the files come from initially, and what are you doing with them. Etc...

As much information as you can provide about what the high level problem is may help us recommend a much cleaner or simpler (and faster) solution.

With Robocopy you can copy only newer or changed files, and with the XF option you can excluded selected file patterns like *.mp3, *.wav etc.  But there's no easy way for it to only copy folders that have .FLAC files in them, it would copy all matching file extensions from all folders, even if there weren't any FLAC files there.  It wouldn't copy the MP3, WAV etc ones you want to exclude, but I don't know if that would be close enough.  I'd really like to understand the root problem better.

~bp
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36896950
Currently scripting something... Almost there...
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36896973
Here you go.

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET FolderSource=C:\Music
SET FolderDest=C:\Target
SET ExtInclude=flac
SET ExtExclude=*.mp3 *.acc *.wav

SET Flag=0

REM CREATING SAMPLE TEST FOLDERS
	IF NOT EXIST "%FolderSource%\1\1" MD "%FolderSource%\1\1"
	IF NOT EXIST "%FolderSource%\1\2" MD "%FolderSource%\1\2"
	IF NOT EXIST "%FolderSource%\2\1" MD "%FolderSource%\2\1"
	IF NOT EXIST "%FolderSource%\2\2" MD "%FolderSource%\2\2"
	IF NOT EXIST "%FolderSource%" MD "%FolderSource%"
	IF NOT EXIST "%FolderDest%" MD "%FolderDest%"
	
REM CREATING SAMPLE TEST FILES
	FOR %%A IN (flac,txt,jpg) DO ECHO TEST FILE>"%FolderSource%\1\1\test.%%A"
	FOR %%A IN (flac,txt,jpg,mp3,wav) DO ECHO TEST FILE>"%FolderSource%\1\2\test.%%A"
	FOR %%A IN (txt,jpg,mp3) DO ECHO TEST FILE>"%FolderSource%\2\1\test.%%A"
	FOR %%A IN (txt,jpg) DO ECHO TEST FILE>"%FolderSource%\2\2\test.%%A"

	
REM FINDING FOLDERS CONTAINING WANTED EXTENSIONS
	FOR /F "delims=" %%A IN ('DIR /AD /B /S "%FolderSource%"') DO (
		FOR /F "delims=" %%B IN ('DIR /A-D /B "%%A\*.%ExtInclude%"') DO SET Flag=1
		IF !Flag! EQU 1 (
			SET FolderDestFull=%FolderDest%%%~pnxA
			IF NOT EXIST "!FolderDestFull!" MD "!FolderDestFull!"
			Robocopy "%%A" "!FolderDestFull!" * /COPYALL /MIR /NDL /R:0 /TEE /XJD /FP /TS /NP /XF %ExtExclude% 
		)
		SET Flag=0
	)
PAUSE
EXIT

Open in new window

0
 

Author Comment

by:TheOnly4u
ID: 36896991
I'll show you again with a complete example:

Let's say F:\Musikk\ contain this:
F:\Musikk\Dont want this folder\Dontwant this song.wav
F:\Musikk\Dont want this folder\Dontwant this jpeg.jpg
F:\Musikk\Dont want this folder\Dontwant this text.txt
F:\Musikk\I want this folder\I want this song.flac
F:\Musikk\I want this folder\I want this song2.flac
F:\Musikk\I want this folder\Dont want this song1.mp3
F:\Musikk\I want this folder\Dont want this song2.mp3
F:\Musikk\I want this folder\I want this text.txt
F:\Musikk\I want this folder\I want this Jpeg.jpg
F:\Musikk\I want this folder\subFolder I want\I want this Jpeg.jpg
F:\Musikk\I want this folder\subFolder I want\I want this Jpeg2.jpg
F:\Musikk\I want this folder\subFolder I want\I want this Gif3.gif
F:\Musikk\I want this folder\subFolder I want\Dont want this song.wav

What I want to end up with at D:\Musikk is:
D:\Musikk\I want this folder\I want this song.flac
D:\Musikk\I want this folder\I want this song2.flac
D:\Musikk\I want this folder\I want this text.txt
D:\Musikk\I want this folder\I want this Jpeg.jpg
D:\Musikk\I want this folder\subFolder I want\I want this Jpeg.jpg
D:\Musikk\I want this folder\subFolder I want\I want this Jpeg2.jpg
D:\Musikk\I want this folder\subFolder I want\I want this Gif3.gif

0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36896994
Was your message intended to me?
Thanks what my script is doing!
0
 

Author Comment

by:TheOnly4u
ID: 36896996
sry ReneGe, was talking to billprew
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 36896999
I understood the file manipulations you had originally requested, but that doesn't help me understand why you are doing it, and how the files are used, and created, etc. I just felt that might help us understand the context better, and potentially suggest some approaches you hadn't considered, since this file manipulation is getting a bit ugly, and slow.

~bp
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897001
Here is the production script

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET FolderSource=F:\Musik
SET FolderDest=D:\
SET ExtInclude=flac
SET ExtExclude=*.mp3 *.acc *.wav

SET Flag=0

FOR /F "delims=" %%A IN ('DIR /AD /B /S "%FolderSource%"') DO (
	FOR /F "delims=" %%B IN ('DIR /A-D /B "%%A\*.%ExtInclude%"') DO SET Flag=1
	IF !Flag! EQU 1 (
		SET FolderDestFull=%FolderDest%%%~pnxA
		IF NOT EXIST "!FolderDestFull!" MD "!FolderDestFull!"
		Robocopy "%%A" "!FolderDestFull!" * /COPYALL /MIR /NDL /R:0 /TEE /XJD /FP /TS /NP /XF %ExtExclude% 
	)
	SET Flag=0
)
PAUSE
EXIT

Open in new window

0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897005
Have you try my script?
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897015
By the way... good morning bp!
0
 
LVL 51

Expert Comment

by:Bill Prew
ID: 36897019
"Good afternoon" Rene.

~bp
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36897020
OK, in which case it should be just the additon of an "/e" to the xcopy for those file types and it will do the subdirs too.  Gave it a quick test like this but just moved to a new PC and not got my original test set of folders on here at the mo, seems OK though:

Steve


@echo off
setlocal enabledelayedexpansion

set source=f:\musikk
set dest=d:\musikk

REM Change "D:" in the line "set destdir=" to the destination drive letter
REM only works as long as the source path and dest. path are the same except drive letter.
REM Otherwise will have to do some more clever processing!

set include=jpg,cue,log,txt,png,gif
set logfile="%source%\log.txt"
set copied="%source%\copied.txt"
set FilesCopied="File(s) copied"

echo Looking for FLAC files to copy
xcopy /y /d /s "%source%\*.flac" "%dest%" > %copied% 2>%logfile%
  if errorlevel 1 echo There was an error %errorlevel% copying >>%logfile%

set sourcedir=
for /f "tokens=*" %%A in ('type "%copied%" ^| find /v %FilesCopied%') do (

  REM Check if the directory to copy is different to the last one
  if NOT "%%~dpA"=="!sourcedir!" (

    REM Get the directory and drive only
    set sourcedir=%%~dpA

    REM replace source path with dest
    set destdir=d:%%~pA

    echo Directory %%~dpA being copied
    echo Directory %%~dpA being copied >>%logfile%

    REM work down extensions in include variable and copy
    for %%T in (%include%) do (
      xcopy /e/d "%%~dpA*.%%T" "!destdir!" 2>NUL | FIND /V %FilesCopied% >>%LOGFILE% 2>&1
    )
  )
)
notepad %logfile%

Open in new window

0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897028
Good afternoon Steve :)
Today's Three Musketeers: Rene, Bill and Steve, to the rescue...
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36897076
Same to you! Eventually replaced this main machine which still had W2K on with a new Win 7 one.... 11 years of stuff to put back on.... plus that I had brought over from previous Win9x machines before that so don't suppose I'll have much time for EE for a bit.

Steve
0
 

Author Comment

by:TheOnly4u
ID: 36897129
Okay I've tested both scripts.

dragon-it: yours work fine first time -  second time it only updates if a new flac is there, not if lets say a txt file or jpg is added renamed etc to the folders that contain the copied flac.

ReneGe: Yours work very nice, also on second and third etc, it pick up any changes. Only thing was the it puts everything into a subfolder in the destination folder  ex:
Source is F:\Musikktest
Destina. is: D:\Musikktest

Then Folder "F:\Musikktest\CoolMusic\CoolFlac\Eagles\HotelCalif.flac" becomes
D:\Musikktest\Musikktest\CoolMusic\CoolFlac\Eagles\HotelCalif.flac

Now I solve this with seting Destination to D: ,  but if I want to copy from F: to D:, how will this work? dont have a drive free to try on.

0
 

Author Comment

by:TheOnly4u
ID: 36897134
And my second question for ReneGe: Is it only possible to use exclusion or can include be used instead? there are situation where include is best and others where exclude is the best option.
0
 

Author Comment

by:TheOnly4u
ID: 36897263
To billprew..and ReneGe and dragon-it

I handle alot of files personly in my ever expanding music collection. I live in Norway where we have a nice law with regards to music rights. It's as strict as anywhere else except for one tiny amendment: Real life friends(not facebook or other internet friends) and family can make a copy of a music cd/mp3/flac etc file that they own and share with eachother.

Since I'm heavly into Ultra High End HiFi, I get alot of real life friends with exstensive music collections... and we all use Flac. But most of use have be gathering for decads(in my case since cdplayer first came on the market). There for we have ALOT of various filetypes in addition to flac. In addition there all this support filetypes for the music formats from hundred different music programs to take into account.

All this is but into a 15 TB NAS with online backup( a small service to my friends). It's from this Massive moltingpot of music and other files I need to extract what I need. In this case it's flac with their support files.

Atm there is only about 6600 flac files, but I know for a fact that this will increase to 14000+ within about 6 months. That's just the flac files. the NAS will contain about 150-180k relevant files in the F:\Musikk Folder within a few months.

This why I need help to sort all these files, with the "special" option that is mentioned.

Secondly I'm the IT-guru in my family/friend circle. ReneGe's script working with both include and exclude seperatly would dramaticly save me time when I'm helping them clean up their mess/ saving doc docx jpg mov mp3 etc all over the place. That is why an include to ReneGe's script would be most effective and time saving for me. It basicly mean I can Just edit the include or exclude and then click on the bat file, and best of all...leave and something else...like listen to music.

I'm 20% medicly invalid and 90% work disabled, so I have alot of time, but the pain prevents me from using the PC for longer times.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36897287
"dragon-it: yours work fine first time -  second time it only updates if a new flac is there, not if lets say a txt file or jpg is added renamed etc to the folders that contain the copied flac."

That's what it was designed to do.  How is it supposed to identify otherwise all changed files when it doesn't know whether ti include them or not based on a different dir.

What we would have to do then is scan down ALL Flac files every time instead of this way and then execute a copy for each of those dirs.

Quite do-able and will look later but busy getting kids sorted for next few hours...

Roughly:

dir /s /b *.flac
For all those .Flac files.  When dir changes then copy all FLAC files for that dir and the current subdirs etc.


Steve



0
 

Author Comment

by:TheOnly4u
ID: 36897289
Tell me if I'm not on the right path here, I'm just thinking out loud.

If include cant be used, can I use the exlude this way:

Example:
I want folders containing flac files AND for this example txt and jpg. I'll use the whole alphabet like this *.a* *.b* etc then I add att then end *.txt *.jpg...
SET FolderSource=F:\Musik
SET FolderDest=D:\
SET ExtInclude=flac
SET ExtExclude=*.a* *.b* *.c* *.d*  *.j* *.t* *.jpg *.txt

Just an Idea
0
 

Author Comment

by:TheOnly4u
ID: 36897291
Thx dragon-it..I sure appriciate your help.
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897293
@36897129: So you don,t want the destination to keep the same path structure of the source?
@36897134: You can use both, inclusions and exclusions.

Here is the updates script

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET FolderSource=F:\Musik
SET FolderDest=D:\
SET ExtRequired=flac
SET Include=*.flac *.txt
SET Exclude=*.mp3 *.acc *.wav

SET Flag=0

FOR /F "delims=" %%A IN ('DIR /AD /B /S "%FolderSource%"') DO (
	FOR /F "delims=" %%B IN ('DIR /A-D /B "%%A\*.%ExtRequired%"') DO SET Flag=1
	IF !Flag! EQU 1 (
		SET FolderDestFull=%FolderDest%%%~pnxA
		IF NOT EXIST "!FolderDestFull!" MD "!FolderDestFull!"
		Robocopy "%%A" "!FolderDestFull!" %Include% /COPYALL /MIR /NDL /R:0 /TEE /XJD /FP /TS /NP /XF %Exclude% 
	)
	SET Flag=0
)
PAUSE
EXIT

Open in new window

0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897302
Note, that I did not consider 36897129 in my update.
0
 

Author Comment

by:TheOnly4u
ID: 36897312
ReneGe..

yes I want the Folder structure but from the Source point iow if Source is F:\Musikk and destination is D:\MusikkFlac then it shouldnt be like

F:\Musikk\CoolMusic\Eagles\Album\song.flac
to
D:\MusikkFlac\Musikk\CoolMusic\Eagles\Album\song.flac

It should end up like
D:\MusikkFlac\CoolMusic\Eagles\Album\song.flac
0
 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 250 total points
ID: 36897316
Actually easier change than I thought.  This is it I think:
@echo off
setlocal enabledelayedexpansion

set source=e:\musikk
set dest=d:\musikk

set include=flac,jpg,cue,log,txt,png,gif
set logfile="%source%\log.txt"
set copied="%source%\copied.txt"
set FilesCopied="File(s) copied"

echo Looking for FLAC files to copy

set sourcedir=
for /f "tokens=*" %%A in ('dir "%source%\*.flac" /s /b') do (

  REM Check if the directory to copy is different to the last one
  if NOT "%%~dpA"=="!sourcedir!" (

    REM Get the directory and drive only
    set sourcedir=%%~dpA

    REM replace source path with dest
    set destdir=d:%%~pA

    echo Directory %%~dpA being copied
    echo Directory %%~dpA being copied >>%logfile%

    REM work down extensions in include variable and copy.  This now includes FLAC so they are copied too.
    for %%T in (%include%) do (
      xcopy /e/d "%%~dpA*.%%T" "!destdir!" 2>NUL | FIND /V %FilesCopied% >>%LOGFILE% 2>&1
    )
  )
)
notepad %logfile%

Open in new window

0
 

Author Comment

by:TheOnly4u
ID: 36897325
Nice dragon-it

Give me a few minutes to setup a test
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36897347
If it does work OK then the use of a "dir" does mean it will go all through ALL flac files first then start processing.

Better would be to use the for /r syntax but we can substitute that in if it works as you want.

Steve
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897355

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET FolderSource=F:\Musik
SET FolderDest=D:\
SET Required=flac
SET Include=*.flac *.txt
SET Exclude=*.mp3 *.acc *.wav

SET Flag=0

FOR /F "delims=" %%A IN ('DIR /AD /B /S "%FolderSource%"') DO (
	FOR /F "delims=" %%B IN ('DIR /A-D /B "%%A\*.%Required%"') DO SET Flag=1
	IF !Flag! EQU 1 (
		SET FolderDestFull=%FolderDest%%%~pnxA
		SET FolderDestFull=!FolderDestFull:Musik=Musik%Required%!
		IF NOT EXIST "!FolderDestFull!" MD "!FolderDestFull!"
		Robocopy "%%A" "!FolderDestFull!" %Include% /COPYALL /MIR /NDL /R:0 /TEE /XJD /FP /TS /NP /XF %Exclude% 
	)
	SET Flag=0
)
PAUSE
EXIT

Open in new window

0
 

Author Comment

by:TheOnly4u
ID: 36897359
dragon-it

The log file you create, is it for my benefite, or does the script use it to check for something? The reason I ask is because Renege's script seems to work faster.

Btw it looks like it's working good, havent tried all but that will take  days of testing.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36897380
It doesn't need the log file, I don't think that will take up too much extra time but just remove all the >>logfile bits if not.

Like I say if that is OK I suggest changing it to for /r instead:

for /r %%a in (*.flac) do (

i.e. as below... and without logfile now too if preferred:

@echo off
setlocal enabledelayedexpansion

set source=e:\musikk
set dest=d:\musikk

set include=flac,jpg,cue,log,txt,png,gif
set copied="%source%\copied.txt"
set FilesCopied="File(s) copied"

echo Looking for FLAC files to copy

set sourcedir=
for /r %%A in (*.flac) do (

  REM Check if the directory to copy is different to the last one
  if NOT "%%~dpA"=="!sourcedir!" (

    REM Get the directory and drive only
    set sourcedir=%%~dpA

    REM replace source path with dest
    set destdir=d:%%~pA

    echo Directory %%~dpA being copied

    REM work down extensions in include variable and copy.  This now includes FLAC so they are copied too.
    for %%T in (%include%) do (
      xcopy /e/d "%%~dpA*.%%T" "!destdir!" 2>NUL | FIND /V %FilesCopied%
    )
  )
)

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36897392
ReneGe approach effectively is:

find all dirs
in each of those dirs look to see if there is a flac file
copy the right files with robocopy

Mine was originally

find all new flac files
in each of those dirs copy the extra files

and then

find all new flac files
in each of those dirs copy extra files
and copy empty subdirs

and then

find all new flac files
in each of those dirs copy extra files and subdirs

Now it runs down every Flac file so it is going to be less efficient that ReneGe's aproach.  Mine was built originally on trying to find files that had changed rather than blindly changing every dir.

If you have added flac files and related files but not any other extra files then my previous script would probably be quicker.

anyway give them a try.  I think both are now on the same lines as you are, but time will tell!!

Also it would most likely be quicker to write this in VBScript now as there is a lot of loop processing.  Originally it was OK in batch since it was doing an xcopy and parsing a few directories from there.

Steve
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897427
Here is an improved version.

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET SourceDrive=F:
SET SourceFolder=Musik
SET TargetDrive=D:
SET Required=flac
SET Include=*.flac *.txt
SET Exclude=*.mp3 *.acc *.wav

SET Flag=0

FOR /F "delims=" %%A IN ('DIR /AD /B /S "%SourceDrive%\%SourceFolder%"') DO (
	FOR /F "delims=" %%B IN ('DIR /A-D /B "%%A\*.%Required%"') DO SET Flag=1
	IF !Flag! EQU 1 (
		SET TargetDriveFull=%TargetDrive%%%~pnxA
		SET TargetDriveFull=!TargetDriveFull:%TargetDrive%\%SourceFolder%=%TargetDrive%\%SourceFolder%%Required%!
		IF NOT EXIST "!TargetDriveFull!" MD "!TargetDriveFull!"
		Robocopy "%%A" "!TargetDriveFull!" %Include% /COPYALL /MIR /NDL /R:0 /TEE /XJD /FP /TS /NP /XF %Exclude% 
	)
	SET Flag=0
)
PAUSE
EXIT

Open in new window

0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897432
@TheOnly4u:

If you prefer my script, feel free to split points with Steve and Bill.

Cheers,
Rene
0
 

Author Comment

by:TheOnly4u
ID: 36897472
Okay  atm dragon-it's script works fine for include with for /f as in post 36897316.

ReneGe, your script in post 36897001 works just fine for exclude except that it create the Source folder as a subfolder in the destination folder.
Your script in post 36897427 work fine as include a part that it create it places the sourcefolder content in D:\Musikktestflac when the destination is D:
I need to be able to shoose my destination folder precisly.  that is f.ex:
with sourcefolder D:\Musikk and Destination folder D:\Newfolder, then:
the file Song1.flac as in F:\Musikk\Song1.flac should go to D:Newfolder   like this
D:\Newfolder\Song1.flac

But we're getting close now.
0
 

Author Comment

by:TheOnly4u
ID: 36897475
dragon-it what would changing for /f to for /r do?
0
 
LVL 10

Accepted Solution

by:
ReneGe earned 250 total points
ID: 36897491
/R gets extremly slow when it come to large quantity of files.

@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET SourceDrive=F:
SET SourceFolder=Musik
SET TargetDrive=D:
SET TargetFolder=Newfolder
SET Required=flac
SET Include=*.flac *.txt
SET Exclude=*.mp3 *.acc *.wav

SET Flag=0

FOR /F "delims=" %%A IN ('DIR /AD /B /S "%SourceDrive%\%SourceFolder%"') DO (
	FOR /F "delims=" %%B IN ('DIR /A-D /B "%%A\*.%Required%"') DO SET Flag=1
	IF !Flag! EQU 1 (
		SET TargetDriveFull=%TargetDrive%%%~pnxA
		SET TargetDriveFull=!TargetDriveFull:%TargetDrive%\%SourceFolder%=%TargetDrive%\%TargetFolder%!
		IF NOT EXIST "!TargetDriveFull!" MD "!TargetDriveFull!"
		Robocopy "%%A" "!TargetDriveFull!" %Include% /COPYALL /MIR /NDL /R:0 /TEE /XJD /FP /TS /NP /XF %Exclude% 
	)
	SET Flag=0
)
PAUSE
EXIT

Open in new window

0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897536
@Steve,
In hoping I could learn some few extra new tricks from you, do you think my script could get fitter or smarter?

Cheers
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36897538
for /f -- it runs the whole dir command, then starts to look at the output.
for /r -- it should start processing sooner.

Steve
0
 

Author Comment

by:TheOnly4u
ID: 36897539
Perfect ReneGe, that was include in the wraps.

Now how to get your exclude in post 36897001 to work similar to post 36897491 in terms of choose your own destination folder. When we have that exlude working good, you can put both in a post and I'll choose that post and dragon-it's post 36897316 as Multiple Solutions, and share the points anyway you like
0
 

Author Comment

by:TheOnly4u
ID: 36897542
dragon-it, the script in post 36897380 with for /f didnt work at all...just started cmopying somewhere I cant find and never stopped. But the Script in post 36897316 work just fine as include.
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897556
FROM: 36897380
Change:for /r %%A in (*.flac)
TO:FOR /F "delims=" %%A in ('DIR /S /B *.flac')
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897563
Correction:
For your question @36897542
FROM: 36897380
Change:for /r %%A in (*.flac)
TO:FOR /F "delims=" %%A in ('DIR /S /B "%Source%\*.flac"')
 
0
 

Author Comment

by:TheOnly4u
ID: 36897584
Nop the suggestion in 36897563 dint work it starts the cmd the close it in a spilt second. no copying done at all.
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897587
What if you accept my working solution and split points?
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36897592
It did'nt came out right!!

Let's try again...

Why would'nt you accept my working solution and split points?

(better)

Cheers,
Rene
0
 

Author Comment

by:TheOnly4u
ID: 36897630
Hehe...

This is where we stand atm.
For include we have 2 working solutions
for Exclude we have one sort of working solution.

Include dragon-it post 36897316
 
@echo off
setlocal enabledelayedexpansion

set source=e:\musikk
set dest=d:\musikk

set include=flac,jpg,cue,log,txt,png,gif
set logfile="%source%\log.txt"
set copied="%source%\copied.txt"
set FilesCopied="File(s) copied"

echo Looking for FLAC files to copy

set sourcedir=
for /f "tokens=*" %%A in ('dir "%source%\*.flac" /s /b') do (

  REM Check if the directory to copy is different to the last one
  if NOT "%%~dpA"=="!sourcedir!" (

    REM Get the directory and drive only
    set sourcedir=%%~dpA

    REM replace source path with dest
    set destdir=d:%%~pA

    echo Directory %%~dpA being copied
    echo Directory %%~dpA being copied >>%logfile%

    REM work down extensions in include variable and copy.  This now includes FLAC so they are copied too.
    for %%T in (%include%) do (
      xcopy /e/d "%%~dpA*.%%T" "!destdir!" 2>NUL | FIND /V %FilesCopied% >>%LOGFILE% 2>&1
    )
  )
)
notepad %logfile%

Open in new window


Include ReneGe post 36897491 Here include works fine and it doesnt matter what you put into Exculde if anything...
 
@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET SourceDrive=F:
SET SourceFolder=Musik
SET TargetDrive=D:
SET TargetFolder=Newfolder
SET Required=flac
SET Include=*.flac *.txt
SET Exclude=*.mp3 *.acc *.wav

SET Flag=0

FOR /F "delims=" %%A IN ('DIR /AD /B /S "%SourceDrive%\%SourceFolder%"') DO (
	FOR /F "delims=" %%B IN ('DIR /A-D /B "%%A\*.%Required%"') DO SET Flag=1
	IF !Flag! EQU 1 (
		SET TargetDriveFull=%TargetDrive%%%~pnxA
		SET TargetDriveFull=!TargetDriveFull:%TargetDrive%\%SourceFolder%=%TargetDrive%\%TargetFolder%!
		IF NOT EXIST "!TargetDriveFull!" MD "!TargetDriveFull!"
		Robocopy "%%A" "!TargetDriveFull!" %Include% /COPYALL /MIR /NDL /R:0 /TEE /XJD /FP /TS /NP /XF %Exclude% 
	)
	SET Flag=0
)
PAUSE
EXIT

Open in new window


Exclude ReneGe post 36897001 It's work just fine as exclude But as I explained earlier I need to be able to shoose my destination folder precisly.  that is f.ex:
with sourcefolder D:\Musikk and Destination folder D:\Newfolder, then:
the file Song1.flac as in F:\Musikk\Song1.flac should go to D:Newfolder   like this
D:\Newfolder\Song1.flac
ATM the underlying script make it:
D:\Newfolder\Musikk\Song1.flac
You fixed this for the Include script in post 36897491, what does need changing to make happen here?
 
@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET FolderSource=F:\Musik
SET FolderDest=D:\
SET ExtInclude=flac
SET ExtExclude=*.mp3 *.acc *.wav

SET Flag=0

FOR /F "delims=" %%A IN ('DIR /AD /B /S "%FolderSource%"') DO (
	FOR /F "delims=" %%B IN ('DIR /A-D /B "%%A\*.%ExtInclude%"') DO SET Flag=1
	IF !Flag! EQU 1 (
		SET FolderDestFull=%FolderDest%%%~pnxA
		IF NOT EXIST "!FolderDestFull!" MD "!FolderDestFull!"
		Robocopy "%%A" "!FolderDestFull!" * /COPYALL /MIR /NDL /R:0 /TEE /XJD /FP /TS /NP /XF %ExtExclude% 
	)
	SET Flag=0
)
PAUSE
EXIT

Open in new window


When I get that complete code in a post I'll choose that post together with Posts 36897316 and 36897491 as Multiple Solutions.

thx
TO
0
 

Assisted Solution

by:TheOnly4u
TheOnly4u earned 0 total points
ID: 36897933
Okay then I got the exclude to work... Thx to dragon-it, ReneGe and billprew for stickin with me in my odd request.

Thx to dragon-it for solution for include in post 36897316:
 
@echo off
setlocal enabledelayedexpansion

set source=e:\musikk
set dest=d:\musikk

set include=flac,jpg,cue,log,txt,png,gif
set logfile="%source%\log.txt"
set copied="%source%\copied.txt"
set FilesCopied="File(s) copied"

echo Looking for FLAC files to copy

set sourcedir=
for /f "tokens=*" %%A in ('dir "%source%\*.flac" /s /b') do (

  REM Check if the directory to copy is different to the last one
  if NOT "%%~dpA"=="!sourcedir!" (

    REM Get the directory and drive only
    set sourcedir=%%~dpA

    REM replace source path with dest
    set destdir=d:%%~pA

    echo Directory %%~dpA being copied
    echo Directory %%~dpA being copied >>%logfile%

    REM work down extensions in include variable and copy.  This now includes FLAC so they are copied too.
    for %%T in (%include%) do (
      xcopy /e/d "%%~dpA*.%%T" "!destdir!" 2>NUL | FIND /V %FilesCopied% >>%LOGFILE% 2>&1
    )
  )
)
notepad %logfile%

Open in new window


Thx to ReneGe for solution for Include in post 36897491:
 
@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET SourceDrive=F:
SET SourceFolder=Musik
SET TargetDrive=D:
SET TargetFolder=Newfolder
SET Required=flac
SET Include=*.flac *.txt
SET Exclude=*.mp3 *.acc *.wav

SET Flag=0

FOR /F "delims=" %%A IN ('DIR /AD /B /S "%SourceDrive%\%SourceFolder%"') DO (
	FOR /F "delims=" %%B IN ('DIR /A-D /B "%%A\*.%Required%"') DO SET Flag=1
	IF !Flag! EQU 1 (
		SET TargetDriveFull=%TargetDrive%%%~pnxA
		SET TargetDriveFull=!TargetDriveFull:%TargetDrive%\%SourceFolder%=%TargetDrive%\%TargetFolder%!
		IF NOT EXIST "!TargetDriveFull!" MD "!TargetDriveFull!"
		Robocopy "%%A" "!TargetDriveFull!" %Include% /COPYALL /MIR /NDL /R:0 /TEE /XJD /FP /TS /NP /XF %Exclude% 
	)
	SET Flag=0
)
PAUSE
EXIT

Open in new window


Thx to ReneGe for the above solution that I've altered to Exclude:
 
@ECHO OFF

SETLOCAL ENABLEDELAYEDEXPANSION

SET SourceDrive=F:
SET SourceFolder=Musikktest
SET TargetDrive=D:
SET TargetFolder=Newfolder
SET Required=flac
SET Include=*.flac *.txt
SET Exclude=*.nfo *.wav *.m* *.d*

SET Flag=0

FOR /F "delims=" %%A IN ('DIR /AD /B /S "%SourceDrive%\%SourceFolder%"') DO (
	FOR /F "delims=" %%B IN ('DIR /A-D /B "%%A\*.%Required%"') DO SET Flag=1
	IF !Flag! EQU 1 (
		SET TargetDriveFull=%TargetDrive%%%~pnxA
		SET TargetDriveFull=!TargetDriveFull:%TargetDrive%\%SourceFolder%=%TargetDrive%\%TargetFolder%!
		IF NOT EXIST "!TargetDriveFull!" MD "!TargetDriveFull!"
		Robocopy "%%A" "!TargetDriveFull!" /COPYALL /MIR /NDL /R:0 /TEE /XJD /FP /TS /NP /XF %Exclude% 
	)
	SET Flag=0
)
PAUSE
EXIT

Open in new window


Solution Accepted and points awarded shortly

Cheers and thx for all help
TO
If you ever need advice on Hifi and Home Cinema, let me know and I'll guide towards whatever your taste and wallet dictats.
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36898021
Yr welcome
0
 

Author Closing Comment

by:TheOnly4u
ID: 36923058
Thx for helping guys.

These solutions have a wider use then my Music collection. It's excellent tools for anyone managing larger volumes. Try them for your self and see how effective they are.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36898074
No problem, was an interesting one!

Steve
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

First some basics on Windows 7 Backup.  It has 2 components one is a file based backup which is stored in .zip files each zip is split at around 200 Megabytes and there is the Image Backup which is as the name implies a total image of the partition …
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
In this Micro Tutorial viewers will learn how to use Boot Corrector from Paragon Rescue Kit Free to identify and fix the boot problems of Windows 7/8/2012R2 etc. As an example is used Windows 2012R2 which lost its active partition flag (often happen…
This Micro Tutorial will teach you the basics of configuring your computer to improve its speed. It will also teach you how to disable programs that are running in the background simultaneously. This will be demonstrated using Windows 7 operating…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now