I really wanted to write with one liner, but I couldn't. I didn't understand how to rename mac because it seems to behave differently from Linux.
The example sentence assumed this time is to rename only the jpg image in the swimsuit image folder.
rename.py
#!/usr/bin/env python
# coding: UTF-8
import sys
import os
import re
a = 1
#Image folder to specify
files = os.listdir('/Users/hage/Pictures/sukumizu/')
for file in files:
jpg = re.compile("jpg")
if jpg.search(file):
os.rename(file, "image%06d.jpg " %(a))
a+=1
else:
pass
This time, I will roughly target only jpg images. Set search to sukima.
If you use this above code, please check the operation for the time being. We are not responsible for phenomena such as the image disappearing regardless of whether it is confirmed or not.
Probably like this when testing
touch vip.jpg sukima.jpg futaba.jpg ookami.jpg
Please prepare a dummy file in a disposable folder without images and check the behavior.
### Image transfer with SCP
Image transfer from scp command in python
#### **`o.py`**
```python
#!/usr/bin/env python
# coding: utf-8
import os,sys,re,shutil,pexpect,datetime
s = 'Forwarding server'
u = 'Login user name'
d = 'Destination directory'
r = 'Image storage location starting with http at the transfer destination'
#Basically, the purpose is to raise SS on the spot, so Desktop is the case at home.
p = 'Image storage location of the transfer source'
t = datetime.datetime.now()
#Because SS is a name that starts with Scr
i = re.compile("^Scr")
#Preparing to give a time stamp
stamp = "{0:02d}".format(t.month) + "{0:02d}".format(t.day) + \
"{0:02d}".format(t.hour) + "{0:02d}".format(t.minute)
#print stamp
files = os.listdir('/Directory with images/')
for file in files:
if i.search(file):
obj = file
obj = p+obj
shutil.copyfile(obj, '%simg%s.png' % (p,stamp))
scp=pexpect.spawn('scp -p %simg%s.png %s@%s:%s' %(p,stamp, u,s, d))
scp.interact()
#Output image save destination
print r + 'img%s.png' % stamp
What's missing is pip or easy-install. When raising SS as much as possible, I tried to raise it in one place (preferably in a place under my control) without distributing it.
It's inconvenient to upload images here and there when it catches fire on SNS! !! !!
Recommended Posts