Move folders based on txt file

Hello,

I need some help trying to move some folders to a new location based on a text file.
All the folders to move are in the same "root" folder like:

e:\bulkfolder\Resumes_and_Cvs-April-30 e:\bulkfolder\RRHH-Notes-May-01

The text file is in the format <destination_path>space<folder_name> for example like

c:\destinationpath\20140430\ Resumes_and_Cvs-April-30 d:\destinationpath\20140501\ RRHH-Notes-May-01

Folders have no spaces in their names.
Sometimes there are folders that do not match, then they can be ignored because i will process them later manually.
Is it possible to do this?

Thanks for reading!

I saw your post yesterday, but waited to reply to see if others chimed in.

I have a perl script that does essentially this (I'll make the minor change to make it work for your situation). You'll need ActivePerl (free, safe) to use it.

But I also think this would be a very cool addition to the Dynamic Renamer - to base renames on names matched from a file. I'd be willing to considering doing adding this.

If you're interested, GPSoftware requests you link our account to get support. I'll ask you to comply with their request. See:

gpsoft.com.au/support/support-request.html

From file rename script may be worth looking at, in case it does what you're thinking of already.

To do what's in the root post here will need a custom script, though. I don't think any existing script can do that yet.

Yes, great. Maybe the OP can use this as the basis for his/her needs.

I was thinking of grabbing some or all of the line in a file, and allowing some transformations to affect the matching and/or using an RE to grab the filename from anywhere in the line. In the OPs case, it would simply be supplying an RE to grab the second whitespace-separated field. But I'll work out the details more clearly as I start thinking about flexibility and usability.

Thanks for the link and feedback.

Hello,

Thanks MrC and leo for the responses, shortly after writing the post i discovered this script on the net that i run with powershell.
I just only have to change the text file and the destination directory as the source folder is always the same.
It tries to match every line of the text file with the folders in the source directory.
I don't know a bit of programming nor scripting tho it works :slight_smile:

[code]$text = gc c:\text\resumes20140501.txt
$dir = Get-ChildItem e:\resumes\2014

foreach ($item in $text) {
foreach ($folder in $dir) {
if ($folder.name -like $item) {
Move-Item "e:\resumes\2014$item" 'e:\Arxive\backs\resumes\2014\03\20140501'
Write-Host "Folder $item moved successfully"
[array]$totalitems += $item
break
}
}
}

""
"Folders moved: $totalitems"[/code]

Thanks for your suggestions. :slight_smile:

Great, and thanks for posting your solution!

[quote="fcarter"] ... Move-Item "e:\resumes\2014\$item" 'e:\Arxive\backs\resumes\2014\03\20140501' ... [/quote]

Are you aware that when using Move-Item as with most commands in powershell it permits wildcards in the path? I suspect this is not your intention, if I am correct you can add the -literalpath parameter like so

Move-Item -literalpath "e:\resumes\2014\$item" 'e:\Arxive\backs\resumes\2014\03\20140501' 

To understand why this could be a problem, call one of your folders test[1. This is a valid folder name but will cause powershell to throw an exception if you don't use -literalpath. Any path with *?[] will result in unexpected result. Move-Item reference doco

Didn't know about that, for sure i will use -literalpath from now on.
Thanks for the info wowbagger :slight_smile: