SoFunction
Updated on 2025-04-06

C# file operation function Create file and determine existence

File creation:

Copy the codeThe code is as follows:
( + "\\");//Create this file
(filePath)       //Return the file name with extension
(filePath) //Returns the file name without extension
(filePath) //Return to the directory where the file is located

The file exists:

Copy the codeThe code is as follows:
( + "\\") 
info = new ( + "\\"); 
(());

Isn't it very simple, but sometimes we may feel unfamiliar with functions like GetFileNameWithoutExtension or GetDirectoryName. In the past, we always foolishly wrote function implementations by ourselves, but it turned out that we could only do it with just one line of code~