1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Powershellでワンライナー(ファイル名に連番を振ってリネーム)

Posted at

はじめに

今はバッチで色々スクリプト組んでますが、やりたいことを簡単に実現させたいので(1行で貼りつけるだけで簡単にできるので楽)

ワンライナー

FilenameReplace.ps1
# ファイル名に連番を振ってリネーム
ls | sort Name | % {$i = 1} {mv $_.Name ("{0:000}.txt" -f $i++)}

# 指定フォルダ移動⇒ファイル一覧ソート⇒in/outセットでファイル名に連番を振ってリネーム
Set-Location bak; Get-ChildItem | Sort-Object Name | ForEach-Object {$i = 1;$j = 0} {if(($i % 2) -eq 1 ) {Move-Item $_.Name ("{0:000}_in.txt" -f $j);$i++} else {Move-Item $_.Name ("{0:000}_out.txt" -f $j);$i++;$j++}}

参考サイト

※関係ないサイトもあるのですが、後で使うことあるかもなので
◆Powershellでファイル名に連番を振ってリネームする
 https://helve-blog.com/posts/powershell/powershell-rename-files-serial-number/

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?