Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

10
LINES

< > BotCompany Repo | #1016338 - makeFileNameUnique_withExtension (by adding .1, .2, .3...)

JavaX fragment (include)

static File makeFileNameUnique_withExtension(File f, S ext) {
  File orig = f;
  int n = 0;
  ext = addPrefixIfNempty(".", dropPrefix(".", ext));
  S name = dropSuffixIC(ext, orig.getName());
  f = new File(dirOfFile(orig), name + ext);
  while (f.exists())
    f = new File(dirOfFile(orig), name + "." + (++n) + ext);
  ret f;
}

Author comment

Began life as a copy of #1015318

download  show line numbers  debug dex   

Travelled to 11 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1016338
Snippet name: makeFileNameUnique_withExtension (by adding .1, .2, .3...)
Eternal ID of this version: #1016338/5
Text MD5: 2f324403be0b46e89483e2503dbfab0b
Author: stefan
Category: javax / io
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2018-10-08 12:36:35
Source code size: 338 bytes / 10 lines
Pitched / IR pitched: No / No
Views / Downloads: 171 / 178
Version history: 4 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1016338 & http://1016338.tinybrain.de