I tried to improve the efficiency of daily work with Python

It is subtle whether it is as efficient as it is, but I tried it in between work.

Overview

It will copy some files locally from the file server. Also create a directory.

background

I am assigned a very new daily task of printing out the task list for the day and distributing it to the person in charge. You need to be prepared to create a directory locally and copy the files from the file server to it. I thought that if I wrote a little code, it would be ready with just one click, so I tried it.

Main paper

Create a directory to store the files for that day locally according to the rule yyyymmdd. After that, copy the task list file from the file server.

First, get the time when the script is executed, and then get the date as a character string based on it.

os.mkdir(path)Create a directory with. This is the end of the first stage.


 Next, get the file list of the directory containing the task list of the file server with ```os.listdir (path) `` `.
 Since the file name to be copied has a common character string [hoge] at the beginning, you can search for the corresponding file with `` `str.startswith (prefix)` ``.
 Since the file list is a list, it searches for files one by one in a loop, and as soon as it is found, it is copied to the directory created from the file server with `` `shutil.copy (src, dst)` ``.

 This completes the preparation for daily work. All you have to do is print it out.

#encode:utf-8

import os import shutil from datetime import datetime

if name == "main":

#Get the current time
today = datetime.now().strftime('%Y/%m/%d %H:%M:%S')
y = datetime.now().strftime('%Y')    
m = datetime.now().strftime('%m')
d = datetime.now().strftime('%d')

#Folder name(yyyymmdd)
dirname = y + m + d
#Create folder
os.mkdir(dirname)

#Directory with files you want to copy.
copydir = 'B:/foo/bar/baz/'
#Get a list of files placed in a directory
files = os.listdir(copydir)

for n in range(len(files)):
	#Copy files with common strings to the yyyymmdd folder
    if files[n].startswith('【hoge】'):
        print(files[n])
        shutil.copy(copydir + files[n] , './' + dirname + '/' + files[n])

### [2016.10.01 postscript]
 [Correction]
 Since it is clearly wrong, I corrected it to ```encode: utf-8``` → ```encoding: utf-8```. Thank you for pointing out in the comments.

 **【sad news】**
 It was said that the daily work was completed as the phase progressed.
 It's the code I wrote, but it doesn't seem to come into play for a while ('ω')
 However, since the function is simple, it may be applicable to other applications.


Recommended Posts

I tried to improve the efficiency of daily work with Python
I tried to find the entropy of the image with python
I tried to get the authentication code of Qiita API with Python.
I tried to streamline the standard role of new employees with Python
I tried to touch the CSV file with Python
I tried to solve the soma cube with python
I tried to summarize the string operations of Python
I tried to easily visualize the tweets of JAWS DAYS 2017 with Python + ELK
I tried to automatically send the literature of the new coronavirus to LINE with Python
I tried to simulate how the infection spreads with Python
I tried to find the average of the sequence with TensorFlow
[Python] I tried to visualize the follow relationship of Twitter
I tried to divide the file into folders with Python
I tried to find out how to streamline the work flow with Excel x Python ②
I tried to find out how to streamline the work flow with Excel x Python ④
I tried to put out the frequent word ranking of LINE talk with Python
I tried to automate the article update of Livedoor blog with Python and selenium.
[Python] I tried to automatically create a daily report of YWT with Outlook mail
I tried to find out how to streamline the work flow with Excel x Python ①
I tried to find out how to streamline the work flow with Excel x Python ③
I tried to compare the processing speed with dplyr of R and pandas of Python
The 15th offline real-time I tried to solve the problem of how to write with python
I tried scraping the ranking of Qiita Advent Calendar with Python
I tried to solve the ant book beginner's edition with python
I tried to automate the watering of the planter with Raspberry Pi
I want to output the beginning of the next month with Python
I tried to create a list of prime numbers with python
I tried to fix "I tried stochastic simulation of bingo game with Python"
I tried to expand the size of the logical volume with LVM
I tried to automatically collect images of Kanna Hashimoto with Python! !!
PhytoMine-I tried to get the genetic information of plants with Python
I tried to get the number of days of the month holidays (Saturdays, Sundays, and holidays) with python
I tried "smoothing" the image with Python + OpenCV
I tried hundreds of millions of SQLite with python
I tried "differentiating" the image with Python + OpenCV
I tried to save the data with discord
I tried to touch the API of ebay
I tried to get CloudWatch data with Python
I tried to correct the keystone of the image
I tried "binarizing" the image with Python + OpenCV
I tried to predict the price of ETF
I tried to vectorize the lyrics of Hinatazaka46!
[Python] I tried to visualize the night on the Galactic Railroad with WordCloud!
I tried to refer to the fun rock-paper-scissors poi for beginners with Python
I tried how to improve the accuracy of my own Neural Network
I tried to automatically extract the movements of PES players with software
(Python) I tried to analyze 1 million hands ~ I tried to estimate the number of AA ~
I tried with the top 100 PyPI packages> I tried to graph the packages installed on Python
I tried to verify and analyze the acceleration of Python by Cython
I tried to analyze the negativeness of Nono Morikubo. [Compare with Posipa]
[Outlook] I tried to automatically create a daily report email with Python
I tried to visualize the text of the novel "Weathering with You" with WordCloud
I tried to predict the behavior of the new coronavirus with the SEIR model.
I tried to find out how to streamline the work flow with Excel × Python, my article summary ★
I tried to verify the speaker identification by the Speaker Recognition API of Azure Cognitive Services with Python. # 1
I tried to verify the speaker identification by the Speaker Recognition API of Azure Cognitive Services with Python. # 2
[Python] I tried to visualize the prize money of "ONE PIECE" over 100 million characters with matplotlib.
A story that didn't work when I tried to log in with the Python requests module
I tried to solve the first question of the University of Tokyo 2019 math entrance exam with python sympy
I tried to learn the sin function with chainer
I tried fp-growth with python