Trying to move files with specific file names from root directory to a subfolder
Posted
by
Justin Reagan
on Stack Overflow
See other posts from Stack Overflow
or by Justin Reagan
Published on 2012-06-20T14:57:27Z
Indexed on
2012/06/20
15:16 UTC
Read the original article
Hit count: 163
powershell
|powershell-v2.0
Hi I'm still pretty new to powershell so I apologize if I ask something that extremely basic. I have a root directory on a tftp server that pulls down config files from routers and other equipment every night. The files are like this IPaddress_YYYYMMDD_TA5000. There is a limitation in the equipment where the files can't be set to move into the root directory on their own.
What I want to do is make a powershell script that will only move the files with the TA5000 part in the filename to the sub directory and only keep the 5 most recent files.
I looked but I couldn't seem to find what I would need to do to parse the file for that specific string. I already have the portion of the script to delete the files based on age that was simple.
Any help on getting started would be appreciated.
Edit: I forgot to post the code I was trying.
Move-Item c:\tftptransferfiles c:\tftptransferfiles\sca | Where-Object {_.name -like "*TA5000*"}
I keep getting a error saying that the item at C:\tftptransferfiles is in use.
© Stack Overflow or respective owner