简体   繁体   English

尝试将具有特定文件名的文件从根目录移动到子文件夹

[英]Trying to move files with specific file names from root directory to a subfolder

Hi I'm still pretty new to powershell so I apologize if I ask something that extremely basic. 嗨,我对Powershell还是很陌生,所以如果我问一些非常基本的问题,我深表歉意。 I have a root directory on a tftp server that pulls down config files from routers and other equipment every night. 我在tftp服务器上有一个根目录,该目录每天晚上从路由器和其他设备中提取配置文件。 The files are like this IPaddress_YYYYMMDD_TA5000. 这些文件就是这样的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. 我要做的是制作一个Powershell脚本,该脚本只会将文件名中带有TA5000部分的文件移动到子目录中,并且仅保留5个最新文件。

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. 我不断收到错误消息,指出C:\\ tftptransferfiles中的项目正在使用中。

Get-ChildItem $path -filter "*TA5000"

或者可能:

Get-ChildItem $path | Where-Object {$_.name -like "*TA5000*"}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM