I have thousands of files like the following in the D: \ queries \ directory
#TIM_DV_ORDERINQUERY.SQL
#TIM_QA_ORDERINQUERY.SQL
#TIM_P1_ORDERINQUERY.SQL
#JACK_DV_SALESQUERY.SQL
#JACK_P1_PRODUCTQUERY.SQL
#ERIK_P1_EMPLOYEE-NY.SQL
#ERIK_P1_EMPLOYEE-TX.SQL
:
I am need a script to move them to folders
G:\queries\#TIM\DV\ORDERINQUERY.SQL
G:\queries\#TIM\QA\ORDERINQUERY.SQL
G:\queries\#TIM\P1\ORDERINQUERY.SQL
G:\queries\#JACK\DV\SALESQUERY.SQL
G:\queries\#JACK\P1\PRODUCTQUERY.SQL
G:\queries\#ERIK\P1\EMPLOYEE-NY.SQL
G:\queries\#ERIK\P1\EMPLOYEE-TX.SQL
In other words, the character before the first _ is a subdirectory in G: \ queries, and then the characters between the first and second _ are a subdirectory inside it, and then the name test is the file name.
I have searched a lot on the Internet and I cannot figure it out. I am new to powershell or any scripts. Any help is appreciated.
source
share