Pages

2023年6月5日月曜日

Windows 10,11 でファイル拡張子を再帰的に一括更新する方法

Windowsでファイルの拡張子を一括置換するには、次の手順を実行します。

1. ファイルをバックアップします。一括置換操作を行う前に、重要なファイルを保護するためにバックアップを作成することを強くおすすめします。

2. PowerShellを開きます。スタートメニューから「PowerShell」を検索して開くか、Shift + 右クリックでフォルダ内の空白スペースをクリックし、「PowerShellウィンドウをここで開く」を選択します。

3. 次のコマンドを使用して、指定されたディレクトリ内のファイルの拡張子を一括置換します。以下のコマンドをPowerShellウィンドウに貼り付けて実行します。


powershell

Get-ChildItem -Recurse -Filter "*.tpl" | Rename-Item -NewName { $_.Name -replace '\.tpl$', '.php' }

※ 上記は .tpl のファイルを再帰的に .php に置換する。


上記のコマンドは、指定されたディレクトリ(およびそのサブディレクトリ)内のすべての.tplファイルを検索し、それらの拡張子を.phpに置換します。

置換する拡張子を変更したい場合は、上記のコマンドの「.tpl」および「.php」を適切な拡張子に変更してください。

注意:この操作はファイルの拡張子を変更するため、慎重に行ってください。誤って重要なファイルの拡張子を変更すると、ファイルが正常に動作しなくなる可能性があります。

2023年5月26日金曜日

[Git] ログ、履歴から特定のファイルを削除する

 経緯

テストデータだが、メールアドレスなどを含むファイルを間違ってコミットしてしまったので、ログからも削除したい。

早速調べたが、どうやらGitには最初からこれに対応するコマンドは用意されておらず拡張機能を追加してやる必要があるようだ。

以下に今回の対応方法をメモする。

2023年4月27日木曜日

[CakePHP4] Controller から コマンドを実行する方法

$commandRunner = new CommandRunner(new Application(ROOT . DS . 'config'), 'cake');
$commandRunner->run([
    'bin' . DS . 'cake',
    'command_name',
    'param1',
    'param2,
]);

上記は

$ bin/cake command_name param1 param2

と同等。

2023年3月6日月曜日

[PHP Code Sniffer] The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line

エラー内容

ERROR | [x] The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line

) と { は同一行に書きなさい!!


修正前

public function sampleFunc(

    int $bookId,

    string $bookName

): ?BookEntity

{

  // ...

}


修正後

public function sampleFunc(

    int $bookId,

    string $bookName

): ?BookEntity {

  // ...

}

2022年4月21日木曜日

[Windows] Tera Term などを使わずにクリックしたらトンネル接続開始にする方法

 今回参考にしたサイト


トンネル接続する

まずは Windows の PowerShell だけを使ってトンネル接続をします。

> ssh [username]@[from_host] -i [secret_file_path] -L [from_port]:[to_host]:[to_port]

例:
ポート:2022 の場合は fhost.com サーバー経由で thost.com サーバーに ポート:22 で接続したいという場合。

fhost.com の 接続アカウントは
host: fhost.com
username: user
key_file: C:\Users\user\.ssh\id_rda.pem

> ssh user@fhost.com -i C:\Users\user\.ssh\id_rda.pem
 -L 2022:thost.com:22

鍵ファイルがユーザーディレクトリ以下(もしくはユーザーを限定的に設定)でなければ警告が出てうまく接続できないので、それについて困ったらこちらを参考にしてください。

PowerShell で sshすると UNPROTECTED PRIVATE KEY FILE

ショートカットを作成

好きなところでショートカットを新規作成する


"項目の場所を入力してください(T)" に以下を入力する。


%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe -NoExit -Command "ssh user@fhost.com -i C:\Users\user\.ssh\id_rda.pem -L 2022:thost.com:22"

"次へ" をクリックするとショートカットの名前を確認されるので好きな名前を入力する。


"完了" をクリックして完了。

Followers