Create a gist now

Instantly share code, notes, and snippets.

Embed
from os import path
from os import listdir
import re
import shutil
import datetime
source_dir = 'workdir'
dest_dir = 'newfiles'
def moveFile(filename, new_filename):
source = path.abspath('./' + source_dir) + '/' + filename
destination = path.abspath('./' + dest_dir) + '/' + new_filename
print(source, destination)
shutil.copy(source, destination)
def getFiles():
p = path.abspath('./' + source_dir)
return listdir(p)
def getDateSubstring(file_name):
pattern = r'(?<=\d{4}).{14}(?=\D)'
matches = re.finditer(pattern, file_name)
for matchNum, match in enumerate(matches):
hour = match.group()
break
return hour
def addSecond(date):
initial_date = datetime.datetime.strptime(date, "%d%m%Y%H%M%S")
result_date = initial_date + datetime.timedelta(seconds=1)
return result_date.strftime("%d%m%Y%H%M%S")
def getNewFilename(file_name):
date = getDateSubstring(file_name)
new_date = addSecond(date)
return file_name.replace(date, new_date, 1)
def main():
for filename in getFiles():
new_filename = getNewFilename(filename)
moveFile(filename, new_filename)
main()
@darkaxl

This comment has been minimized.

Show comment
Hide comment
@darkaxl

darkaxl Feb 27, 2018

Script en python, ganador del #SysArmyMx Challenge:
http://www.rootzilopochtli.com/2018/02/sysarmymx-challenge/

Owner

darkaxl commented Feb 27, 2018

Script en python, ganador del #SysArmyMx Challenge:
http://www.rootzilopochtli.com/2018/02/sysarmymx-challenge/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment