Skip to main content

System.IO.File-like in Python.

Project description

csharp-like-file

If you've ever used C# and found yourself missing the sheer convenience of System.IO.File and System.IO.Directory, you're not alone. I've always loved how those static methods make file operations feel so effortless, so I decided to bring that same "vibe" to Python.

I originally built this just to scratch my own itch, so it's not meant to be some over-engineered masterpiece. It's just a straightforward tool to help you get things done. If you run into a bug or realize I missed a standard C# method you can't live without, just give me a shout in the issues!

Quick Example

import csdir
import csfile

directory = csdir.create_directory("test_folder")  # This returns a pathlib.Path object
csfile.write_all_text(directory / "hello.txt", "Hello World")

Differences from the C# Version

There are a couple of small "cultural" differences between Python and C# that you should know about.

Encoding (encoding)

I've set the default text encoding to UTF-8. I'm not a big fan of C#'s Encoding.Default (which can be a bit unpredictable depending on your OS). You can always pass your own encoding parameter if you need something specific.

Path Resolution (lexical)

In C#, a path like a/b/.. is usually treated as a pure string operation. In that world, it always simplifies to a. However, Python here is a bit smarter: if b is actually a symlink pointing somewhere else, .. should take you to the real parent of that target.

I personally think the Python way is more reliable, so that's the default here. But if you really want that classic C# behavior, just set the lexical parameter to True. It'll ignore the file system and just crunch the path strings for you.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

csharp_like_file-0.0.7.tar.gz (2.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

csharp_like_file-0.0.7-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

Details for the file csharp_like_file-0.0.7.tar.gz.

File metadata

  • Download URL: csharp_like_file-0.0.7.tar.gz
  • Upload date:
  • Size: 2.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for csharp_like_file-0.0.7.tar.gz
Algorithm Hash digest
SHA256 c4608e5518bb842b2ee7c32d6c616f194b842139f152bbdc36995bd8ecc97afb
MD5 3fc1984ad0b877ab12c3a4039fc1c3e4
BLAKE2b-256 dc51ead6344a9c4a79b103d7979cd5493c14d6473edaec91656071fca4a9d268

See more details on using hashes here.

File details

Details for the file csharp_like_file-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: csharp_like_file-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for csharp_like_file-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 87c3197dbd50cf92f2901c3961883dbcbac56b03a8ab75032e1fa60d730d8b7b
MD5 3037c734def53dec264b0b567504b366
BLAKE2b-256 bb86a725f0bb9f43344dc343968fd14c86a51ec129737a930064fa52cf5dc796

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page