Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
19
Task/Rename-a-file/Processing/rename-a-file-1.processing
Normal file
19
Task/Rename-a-file/Processing/rename-a-file-1.processing
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
void setup(){
|
||||
boolean sketchfile = rename(sketchPath("input.txt"), sketchPath("output.txt"));
|
||||
boolean sketchfold = rename(sketchPath("docs"), sketchPath("mydocs"));
|
||||
// sketches will seldom have write permission to root files/folders
|
||||
boolean rootfile = rename("input.txt", "output.txt");
|
||||
boolean rootfold = rename("docs", "mydocs");
|
||||
// true if succeeded, false if failed
|
||||
println(sketchfile, sketchfold, rootfile, rootfold);
|
||||
}
|
||||
|
||||
boolean rename(String oldname, String newname) {
|
||||
// File (or directory) with old name
|
||||
File file = new File(oldname);
|
||||
// File (or directory) with new name
|
||||
File file2 = new File(newname);
|
||||
// Rename file (or directory)
|
||||
boolean success = file.renameTo(file2);
|
||||
return success;
|
||||
}
|
||||
29
Task/Rename-a-file/Processing/rename-a-file-2.processing
Normal file
29
Task/Rename-a-file/Processing/rename-a-file-2.processing
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
from java.io import File
|
||||
|
||||
def setup():
|
||||
# rename local file
|
||||
sketchfile = rename(sketchPath("input.txt"), sketchPath("output.txt"))
|
||||
# rename local folder
|
||||
sketchfold = rename(sketchPath("docs"), sketchPath("mydocs"))
|
||||
# rename root file (if permitted)
|
||||
rootfile = rename("input.txt", "output.txt")
|
||||
# rename root folder (if permitted)
|
||||
rootfold = rename("docs", "mydocs")
|
||||
|
||||
# display results of four operations: True=success, False=fail
|
||||
println(str(sketchfile) + ' ' +
|
||||
str(sketchfold) + ' ' +
|
||||
str(rootfile) + ' ' +
|
||||
str(rootfold))
|
||||
# output:
|
||||
# True True False False
|
||||
|
||||
|
||||
def rename(oldname, newname):
|
||||
# File (or directory) with old name
|
||||
file = File(oldname)
|
||||
# File (or directory) with new name
|
||||
file2 = File(newname)
|
||||
# Rename file (or directory)
|
||||
success = file.renameTo(file2)
|
||||
return success
|
||||
Loading…
Add table
Add a link
Reference in a new issue