mori– Author –
-
C#樹林
【C#】ファイルの拡張子を変更する (Path.ChangeExtension)
ファイルをリネームする際、特に「拡張子だけを変えたい(例:.jpeg → .jpg)」という場合、手動で文字列操作を行うとドットの位置の判定などでミスが起きがちです。 Path.ChangeExtension メソッドを使用すると、パス文字列内の拡張子部分だけを安全に書... -
C#樹林
[C#] Copying, Moving, and Deleting Files (Basic Operations of the File Class)
File system operations, such as creating file backups, moving processed files, or deleting unnecessary logs, are performed using the static methods of the System.IO.File class. When performing these operations, exceptions (errors) can ea... -
C#樹林
【C#】ファイルのコピー・移動・削除を行う (Fileクラスの基本操作)
ファイルのバックアップ作成や、処理済みファイルの移動、不要なログの削除など、ファイルシステムへの操作は System.IO.File クラスの静的メソッドを使用して行います。 これらの操作を行う際は、対象のファイルが存在しない場合や、移動先に同名のファイ... -
C#樹林
[C#] Converting Relative Paths to Absolute Paths (Full Paths) (Path.GetFullPath)
When "relative paths" (e.g., ..\Data\input.csv) are specified in command line arguments or configuration files, you often need to convert them to "absolute paths" (full paths) inside the program to correctly locate the file. Using the Pa... -
C#樹林
【C#】相対パスを絶対パス(フルパス)に変換する (Path.GetFullPath)
コマンドライン引数や設定ファイルで「相対パス(例:..\Data\input.csv)」が指定された際、プログラム内部ではファイルの場所を特定するために「絶対パス(フルパス)」に変換したい場合があります。 Path.GetFullPath メソッドを使用すると、現在のカレ... -
お金樹林
【ロレックスマラソン】「信用ポイント制」ではありません。その実態を「古本探し」に例えて解説
ロレックスの正規店に通い詰め、希望のモデルを探し求める「ロレックスマラソン」。 言葉は聞いたことがあっても、具体的にどのような仕組みで、なぜそこまでしなければならないのか、疑問に思う方も多いのではないでしょうか。 「常連にならないと売って... -
C#樹林
[C#] Getting Directory Names, Extensions, and Other Components from a File Path
When you want to extract specific parts from a file path string (e.g., C:\MyData\report.pdf), such as "just the file name," "the extension," or "the parent folder path," performing string manipulation (using Substring or IndexOf) can oft... -
C#樹林
【C#】ファイルパスからディレクトリ名や拡張子などの構成要素を個別に取得する
ファイルパス文字列(例:C:\MyData\report.pdf)から、「ファイル名だけ欲しい」「拡張子を調べたい」「親フォルダのパスを知りたい」という場合、文字列操作(Substring や IndexOf)を行うのはバグの原因になります。 System.IO.Path クラスには、これ... -
C#樹林
[C#] Safely Joining File Paths Without Worrying About Separators (Path.Combine)
When building file or directory paths in a program, using simple string concatenation (like the + operator) is dangerous. This is because path separators differ by OS (Windows uses \, Linux/Mac uses /), and mistakes often occur regarding... -
C#樹林
【C#】パスの区切り文字を気にせず安全にファイルパスを結合する (Path.Combine)
ファイルやディレクトリのパスをプログラムで組み立てる際、単なる文字列連結(+ 演算子など)を使用するのは危険です。OSによってパスの区切り文字が異なったり(Windowsは \、Linux/Macは /)、末尾の区切り文字の有無によるミスが発生しやすいためです... -
C#樹林
[C#] Specifying Multiple Regex Options Simultaneously (Combining RegexOptions)
When using regular expressions, you might want to enable "Case Insensitive (IgnoreCase)" and "Multiline Mode (Multiline)" at the same time. Since RegexOptions in C# is defined as bit flags, you can combine multiple options using the bitw... -
C#樹林
【C#】正規表現で複数のオプションを同時に指定する (RegexOptionsの組み合わせ)
正規表現を使用する際、「大文字小文字を区別しない (IgnoreCase)」設定と、「複数行モード (Multiline)」設定を同時に有効にしたい場合があります。 C# の RegexOptions はビットフラグとして定義されているため、ビット演算子の OR (|) を使用することで... -
C#樹林
[C#] Performing Case-Insensitive Regex Searches (RegexOptions.IgnoreCase)
By default, C# Regular Expressions (Regex) strictly distinguish between uppercase and lowercase letters (e.g., "Apple" and "apple" are treated as different). If you want to allow for variations in user input and match text regardless of ... -
C#樹林
【C#】大文字と小文字を区別せずに正規表現で検索する (RegexOptions.IgnoreCase)
C#の正規表現(Regex)は、デフォルトでは大文字と小文字を厳密に区別します(例:"Apple" と "apple" は別物として扱われます)。 ユーザー入力の揺らぎを許容したい場合など、これらを区別せずにマッチさせるには、RegexOptions.IgnoreCase オプションを... -
Python樹林
[Python] Saving and Restoring Running Objects to a File: How to Use pickle
If you want to save (serialize) complex data generated by a Python program, such as class instances, lists, or dictionaries, exactly as they are to a file and restore (deserialize) them later, use the standard library pickle module. Unli... -
Python樹林
【Python】実行中のオブジェクトをファイルに保存・復元する:pickleの使い方
Pythonプログラムで生成したクラスのインスタンスやリスト、辞書などの複雑なデータを、そのままの形でファイルに保存(シリアライズ)し、後から復元(デシリアライズ)したい場合は、標準ライブラリの pickle モジュールを使用します。 JSON形式とは異な... -
Python樹林
[Python] Compress/Archive an Entire Directory at Once: shutil.make_archive
When you want to compress an entire directory (folder) in Python, using the make_archive() function from the standard library shutil module is overwhelmingly easier than writing loop processes with the zipfile or tarfile modules. This fu... -
Python樹林
【Python】ディレクトリごと一括で圧縮・アーカイブする:shutil.make_archive
Pythonでディレクトリ(フォルダ)の中身をまるごと圧縮したい場合、zipfile や tarfile モジュールでループ処理を書くよりも、標準ライブラリ shutil モジュールの make_archive() 関数を使うのが圧倒的に簡単です。 この関数は、1行のコードでディレクト... -
Python樹林
[Python] Compressing and Archiving Files in Tar Format: Writing with tarfile
This article explains how to use Python's tarfile module to group multiple files and directories into a tar archive. In addition to creating simple archives (uncompressed), you can also reduce file size by using compression algorithms li... -
Python樹林
【Python】tar形式でファイルを圧縮・アーカイブする:tarfileの書き込み
Pythonの tarfile モジュールを使用して、複数のファイルやディレクトリをまとめてtarアーカイブを作成する方法を解説します。 単なるアーカイブ(無圧縮)だけでなく、gzipなどの圧縮アルゴリズムを併用してファイルサイズを小さくすることも可能です。 o... -
Python樹林
[Python] How to Extract and Unpack Tar Files: Using the tarfile Module
To handle archive files such as .tar, .tar.gz, and .tgz in Python, use the standard library tarfile module. This format is frequently used for server management and data exchange in Linux environments. What is a Tar File? "Tar (Tape Arch... -
Python樹林
【Python】tarファイルを展開・解凍する方法:tarfileモジュールの使い方
Pythonで .tar, .tar.gz, .tgz などのアーカイブファイルを操作するには、標準ライブラリの tarfile モジュールを使用します。 サーバー管理やLinux環境でのデータ交換などで頻繁に利用される形式です。 Tarファイルとは? 「Tar(Tape Archive)」は、複... -
Python樹林
[Python] Compressing and Creating ZIP Files: Writing and Appending with zipfile
The Python standard library zipfile module allows you to group existing files to create a ZIP archive or add new files to an existing ZIP file. A key point to note is that by default, "compression" is not performed; files are simply bund... -
Python樹林
【Python】ファイルをZIP形式で圧縮・作成する:zipfileの書き込みと追記
Python標準ライブラリの zipfile モジュールを使用すると、既存のファイルをまとめてZIPアーカイブを作成したり、既存のZIPファイルに新しいファイルを追加したりできます。 注意点として、デフォルトの設定では「圧縮」は行われず、単にファイルをまとめ... -
C#樹林
[C#] Splitting Strings by a Specified Regex Pattern (Regex.Split)
The standard String.Split method can only split text by fixed characters like commas or spaces. However, using Regex.Split allows you to convert strings into arrays using flexible rules, such as "splitting where a number appears" or "spl... -
C#樹林
【C#】文字列を指定した正規表現パターンで分割する (Regex.Split)
String.Split メソッドは「カンマ」や「空白」といった固定の文字でしか分割できませんが、Regex.Split を使用すると、「数字が現れた場所で区切る」「カンマまたはセミコロンまたは空白で区切る」といった柔軟なルールで文字列を分割配列に変換できます。... -
C#樹林
[C#] Advanced Replacement with Regex (Substitution Patterns and MatchEvaluator)
While the String.Replace method can only perform simple string substitutions, Regex.Replace enables advanced processing, such as "rewriting parts that match a pattern" or "replacing text with the result of a programmatic calculation." In... -
C#樹林
【C#】正規表現を使った高度な置換処理 (置換パターンとMatchEvaluator)
String.Replace メソッドは単純な文字列の置き換えしかできませんが、Regex.Replace を使用すると、「パターンに一致した部分の書き換え」や「プログラムによる計算結果への置き換え」といった高度な処理が可能になります。 ここでは、「置換パターン($1,... -
C#樹林
[C#] Retrieving “All” Occurrences Matching a Pattern in a String (Regex.Matches)
While Regex.Match retrieves only the "first" match, the Regex.Matches method allows you to retrieve all matching occurrences within a string as a collection (list). This method is essential when you want to extract multiple pieces of dat... -
C#樹林
【C#】文字列の中からパターンに一致する箇所を「すべて」取得する (Regex.Matches)
Regex.Match が「最初の1つ」だけを取得するのに対し、Regex.Matches メソッドを使用すると、文字列内に含まれるすべての一致箇所をコレクション(リスト)として取得できます。 ログファイルからのデータ抽出や、文章内のタグ解析など、複数のデータを取...