Moving files from subdirectories to one directory

DarkTXKnight

Senior member
Oct 3, 2001
933
0
71
I need to move files of the same type from several subdirectories to a new directory but cannot figure out how to do it via command line. This is in windows 7 and I kinda get this from xcopy:

xcopy /s *.mht d:\docs

That copies all the *.mht files from various subdirectories to d:
doc, but it also carries the subdirectory structure which i dont want

I tried switching xcopy for move, and I get an invalid syntax.
If I can get the copy to work like i want then i can deal with deleting the files later, but id really like a move command to work

HELP!
Thanks in advance.
 

DarkTXKnight

Senior member
Oct 3, 2001
933
0
71
Actually I figured that out . Ive written a powershell script like the following:

$files = ls c:\appsyslogs -recurse -Include *.log |foreach-object{copy $_ e:\syslogs}


Problem is that Id like to MOVE instead of copy, and Id like to insert a UNC path instead of a mapped drive.Also how can I create a logfile for what has been moved or not or if there is an attempted file overwrite for duplicates?

 

Paperlantern

Platinum Member
Apr 26, 2003
2,239
6
81
You made me get my powershell out on my win7 box to figure this out, i came up with:

From within the directory you want to copy execute

get-childitem -rec -include *.* | copy-item -destination 'yourpath'

To use a UNC path

cd \\\\server\\\share

Logging is not something ive gotten into all that much, so if anyone else can field that, be my guest.
 

DarkTXKnight

Senior member
Oct 3, 2001
933
0
71
so ive come up with this so far in a test folder:

$files = ls g:\music -recurse -Include *.mp3 |foreach-object{Move-Item $
_ e:\music -force}

This moves all the *.mp3 files to a folder ( will add unc later)and force overwrite if it already exists . If I can figure out how to do logging or at least see progress Id be all set.
 

Paperlantern

Platinum Member
Apr 26, 2003
2,239
6
81
I'm curious why you want all these files in one directory with no subdirectory organization. I know my mp3 collection would be a nightmare without subdirectories
 

DarkTXKnight

Senior member
Oct 3, 2001
933
0
71
modelworks - i tried xxcopy, but it does not work on windows 7 64 unless i want to buy the 64bit license sight unseen, and i wasnt wanting to do that.

Paperlantern - good question. The majority of my mp3's are properly tagged, but not properly named. I had a script that will fix name by tag but it work best if everything is in the same subdirectory . the program then fixes the name and creates a subdirectory from that.

Also I have 6 hard drives that over the years have media files in different places on those drives. If I plug the drive in and run the powershell script from the root, then it moves the mp3s to one massive directory, which would both collect all of the files on my computers, but also weed out the duplicates. I can then seperate the files into a finalized durectory structure once and for all.
 

Paperlantern

Platinum Member
Apr 26, 2003
2,239
6
81
Ahhh very nice, yeah i can see why you wanted to do this now, <3 powershell.

We've been using powershell at work to restructure and move data in a directory with about 60,000 subdirectories in it and its worked like a charm every time.
 

DarkTXKnight

Senior member
Oct 3, 2001
933
0
71
Yeah im loving powershell but still have much to learn. what are you using for resources on powershell?
 

Modelworks

Lifer
Feb 22, 2007
16,240
7
76
You can do it with the cmd line too using two statements, first puts all the files to be copied in a text file , then the second copies the files listed in the text file.

dir *.mp3 /s/b >mp3.txt

for /f "delims=/" %n in (mp3.txt) do copy /y "%n" e:\music

I use the first command all the time to make list of what files are where.
 

Paperlantern

Platinum Member
Apr 26, 2003
2,239
6
81
Originally posted by: DarkTXKnight
Yeah im loving powershell but still have much to learn. what are you using for resources on powershell?

We picked up a book or two, and then of course suppliment anything else with google searches if exactly what we are looking for isnt in the books. I can PM you the book name tomorrow when i go in if you want.
 

tomt4535

Golden Member
Jan 4, 2004
1,758
0
76
you can try robocopy instead of xxcopy in windows 7. It is built in and has greater functionality than xxcopy.
 

Snapster

Diamond Member
Oct 14, 2001
3,916
0
0
You can do this via the gui itself: Search for *.mht, select all the results you require and cut/paste into d:\docs
 

DarkTXKnight

Senior member
Oct 3, 2001
933
0
71
Modelworks - Thank You for the command line way. I still have some uses for that on some machines that don't have the powershell bits loaded up :)

tom - Yeah I started all of this thinking i could do it with robocopy, but the problem with robo and xcopy is that they can search the top level folder recursively and get the *.mp3 or whatevere, but in the destination, they still create the folder structure, just with whatever files were in there by that extension. I would still have to go and pull *.mp3 out of the "new" subdirectories. Is there a switch I am missing?

snapster - Yes you are right of course re: the gui approach, but thing is that I want to be able to set up some scriopts that will just run. Right now Im running the PS script against my windows home server as it copies some 10,000 mp3's to a new server and weeding out the duplicates.

I have other uses for the fancy copying, but the current project is cleaning up what amounts to many weeks of ripping my old CD's and I don't want to have to do that again :)

 

megerdin

Junior Member
Apr 18, 2014
2
0
16
You made me get my powershell out on my win7 box to figure this out, i came up with:

From within the directory you want to copy execute

get-childitem -rec -include *.* | copy-item -destination 'yourpath'

To use a UNC path

cd \\\\server\\\share

Logging is not something ive gotten into all that much, so if anyone else can field that, be my guest.

Thats was nice!