I have thousands of files like the following in a directory called D:queries
#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#TIMDVORDERINQUERY.SQL
G:queries#TIMQAORDERINQUERY.SQL
G:queries#TIMP1ORDERINQUERY.SQL
G:queries#JACKDVSALESQUERY.SQL
G:queries#JACKP1PRODUCTQUERY.SQL
G:queries#ERIKP1EMPLOYEE-NY.SQL
G:queries#ERIKP1EMPLOYEE-TX.SQL
In other words the character before the first _ is the sub directory within G:queries and then the characters between the first _ and the second _ is the a sub directory within it and then the test of the name is the file name.
I have searched a lot on the web and I can't figure it out. I am new to powershell or any kind of scripting. Any help is appreciated.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…