Powershell循环和附加日期 [英] Powershell looping and appending dates
问题描述
我是Powershell的新手我有一个包含多个文件的文件夹超过1200.我想帮助编写一个Powershell脚本,它将循环遍历文件夹并获取每个文件并使用命令行上传工具,上传每个文件,直到lall
文件上传。
文件格式为:filename120170501
脚本命令如下:
$
upload-utility uploadDataSetFile -said ************* -sas **** ************** -sid ******************* -dsid FILE ID -sv 1 -fid FILE_1 -rl 20160316 -f filename120170501.txt -re'文件描述'
$
因此,每次脚本进行循环并抓取文件时,我希望它将文件中的日期追加到脚本中的文件名。
非常感谢别人的帮助。
I'm new to Powershell I have a folder with multiple files in upwards of 1200. I would like some help in writing a Powershell script that would loop through the folder and grab each file and using a command line upload tool, upload each file until lall
files are uploaded.
The files are in this format: filename120170501
The script command goes like this:
upload-utility uploadDataSetFile -said ************* -sas ****************** -sid ******************* –dsid FILE ID -sv 1 -fid FILE_1 -rl 20160316 -f filename120170501.txt -re ‘file description’
So for each time the script makes a loop and grabs a file, I want it to append the date from the file to the filename in the script.
Would really appreciate someone's help.
推荐答案
使用  ;命令" Get-ChildItem folderpath -Recurse | select Name" 将所有文件名导出到csv。并在for循环中使用该文件逐个获取所有文件。
Use command "Get-ChildItem folderpath -Recurse | select Name" to export all file names to a csv. And use that file in a for loop to get all files one by one.
例如,
import-csv filelist.csv | %{
import-csv filelist.csv | %{
upload-utility uploadDataSetFile -said ************* -sas ************** **** -sid ******************* -dsid文件ID -sv 1 -fid FILE_1 -rl 20160316 -f
upload-utility uploadDataSetFile -said ************* -sas ****************** -sid ******************* –dsid FILE ID -sv 1 -fid FILE_1 -rl 20160316 -f
_。名称 -re'文件描述'
_.NAME -re ‘file description’
}
注意:%{} - 简称形式的FOR循环。
Note: %{} - is a short form of FOR loop.
这篇关于Powershell循环和附加日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!