r/programmingrequests • u/I_shot_barney • Apr 04 '17
[X-Post r/learnprogramming] Automate file transfer task in windows, search, move and create new folder
Hi, apologies in advance if this question does not meet the subs criteria, but I will throw it out there anyway. Background, I have no experience at all in programming, but I have a bunch (2000 +) files that need to be organised according to specific parameters. There must be an easier way than doing each one manually. If someone could shed some light on the easiest / quickest way to go about it, would be most appreciative. This is the scenario I want to happen.
*Perform a search in a specified directory (let say c:\files)
*Search sequentially from S0 -> S01 -> S001 ->...->S00001.
*When search returns result (e.g S23) then move files to "designated directory\search term". ( lets say c:\file transfer\S23 )
*If no sub directory exists, a new directory should be created.
*If no search result returned move to next search term ( S24 )
*Repeat until all files have been moved.
Is there a simple way to put this into practice?
2
u/NoG5 Apr 05 '17
you can try this powershell script if i understand correctly, the regex "S\d{1,3}" will match a literal S followed by 1 to 3 digits, the -WhatIf at the end of the move command is for testing if the paths look good remove it and run again
$Source = "C:\files"
$Dest = "C:\file transfer"
Get-ChildItem $Source | ForEach-Object{
if($_.name -match "S\d{1,3}"){
Move-Item $_."$Dest\$($matches[0])\$_" -WhatIf
}
}
2
u/SamSlate Apr 05 '17
Very doable. Is there anything this program does beyond removing zeros from directory names?
Yes? The entire directory?