Repository: spectrochempy/spectrochempy

Issue:
[FEATURE]: scp.write(): set confirm=False as default
### Is your feature request related to a problem?

`write()` opens a dialog box (through a call to `check_filename_to_save()` in utils/file.py , unless `confirm=False` is passed (and `scp.NO_DIALOG` is normally set to `False` except when testing or building the doc).   

### Describe the solution you'd like

When a filename is passed, `write()` should behave as in pandas or numpy, including overwriting the file if it exists. A dialog box should pop up only if no filename is provided. By setting `confirm=False` as the default, one has always the possibility to set it to True if unsure of the path/filename and/or use a test, to warn the enduser e.g.

```
if filename_exists:
   warn(f'{filename} exists and will be overwitten. Please confirm')
   datase.write('dataset.csv', confirm=True)
else
   datase.write('dataset.csv')
```



### Describe alternatives you've considered

 When a filename is passed, a warning+dialog box could be raised by default only if the filename already exists AND confirm=True ? , but having a default behaviour close to pandas or numpy is probably better ?   

### Additional context

_No response_


Discussion:

Resolving patch:
diff --git a/spectrochempy/utils/file.py b/spectrochempy/utils/file.py
--- a/spectrochempy/utils/file.py
+++ b/spectrochempy/utils/file.py
@@ -591,14 +591,17 @@ def get_directory_name(directory, **kwargs):
 
 # ..............................................................................
 def check_filename_to_save(
-    dataset, filename=None, save_as=True, confirm=True, **kwargs
+    dataset, filename=None, save_as=False, confirm=True, **kwargs
 ):
 
     from spectrochempy import NO_DIALOG
 
     NODIAL = NO_DIALOG or "DOC_BUILDING" in environ
 
-    if not filename or save_as:
+    if filename and pathclean(filename).parent.resolve() == Path.cwd():
+        filename = Path.cwd() / filename
+
+    if not filename or save_as or filename.exists():
 
         # no filename provided
         if filename is None or (NODIAL and pathclean(filename).is_dir()):
@@ -619,9 +622,6 @@ def check_filename_to_save(
                 # this is probably due to a cancel action for an open dialog.
                 return
 
-    if pathclean(filename).parent.resolve() == Path.cwd():
-        return Path.cwd() / filename
-
     return pathclean(filename)
 
 


Test patch:
diff --git a/tests/test_core/test_writers/test_exporter.py b/tests/test_core/test_writers/test_exporter.py
--- a/tests/test_core/test_writers/test_exporter.py
+++ b/tests/test_core/test_writers/test_exporter.py
@@ -23,8 +23,15 @@ def test_write():
         scp.write()
 
     # the simplest way to save a dataset, is to use the function write with a filename as argument
-    filename = nd.write("essai.scp")
+    if (cwd / "essai.scp").exists():
+        (cwd / "essai.scp").unlink()
+
+    filename = nd.write("essai.scp")  # should not open a DIALOG
     assert filename == cwd / "essai.scp"
+    assert filename.exists()
+
+    # try to write it again
+    filename = nd.write("essai.scp")  # should open a DIALOG to confirm
 
     nd2 = NDDataset.load(filename)
     testing.assert_dataset_equal(nd2, nd)