Posts: 4,647
Threads: 1,494
Joined: Sep 2016
this is not a joke. it is currently in perl. the "rename" command that i use in linux, although making it work in windows is ok.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
it does not seem to work as a rename command:
Output:
lt2a/forums /home/forums 1> box rename.py
+---<rename.py>---------------------------+
| import pathlib |
| |
| def rename(fname, to): |
| pathlib.Path(fname).rename(to) |
| |
| if __name__ == "__main__": |
| import sys |
| if len(sys.argv) >= 3: |
| fname, to = sys.argv[1:3] |
| rename(fname, to) |
| else: |
| print("rename.py: [from] [to]") |
+-----------------------------------------+
lt2a/forums /home/forums 2> ls -dl foo food
/bin/ls: cannot access 'foo': No such file or directory
/bin/ls: cannot access 'food': No such file or directory
lt2a/forums /home/forums 3> touch foo
lt2a/forums /home/forums 4> ls -dl foo food
/bin/ls: cannot access 'food': No such file or directory
-rw-r--r-- 1 forums forums 0 Apr 2 23:25 foo
lt2a/forums /home/forums 5> py3 rename.py 's/foo/food' foo
Traceback (most recent call last):
File "rename.py", line 10, in <module>
rename(fname, to)
File "rename.py", line 4, in rename
pathlib.Path(fname).rename(to)
File "/usr/lib/python3.5/pathlib.py", line 1279, in rename
self._accessor.rename(self, target)
File "/usr/lib/python3.5/pathlib.py", line 377, in wrapped
return strfunc(str(pathobjA), str(pathobjB), *args)
FileNotFoundError: [Errno 2] No such file or directory: 's/foo/food' -> 'foo'
lt2a/forums /home/forums 6>
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,647
Threads: 1,494
Joined: Sep 2016
that's what makes it challenging. the implementation in Ubuntu is in Perl. i figured if Python had PCRE support, then it might be doable.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.