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)

1  
static File makeFileNameUnique_withExtension(File f, S ext) {
2  
  File orig = f;
3  
  int n = 0;
4  
  ext = addPrefixIfNempty(".", dropPrefix(".", ext));
5  
  S name = dropSuffixIC(ext, orig.getName());
6  
  f = new File(dirOfFile(orig), name + ext);
7  
  while (f.exists())
8  
    f = new File(dirOfFile(orig), name + "." + (++n) + ext);
9  
  ret f;
10  
}

Author comment

Began life as a copy of #1015318

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

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: 352 / 390
Version history: 4 change(s)
Referenced in: [show references]