Skip to content

Instantly share code, notes, and snippets.

@darkaxl darkaxl/
Created Feb 27, 2018

What would you like to do?
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 =
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)

This comment has been minimized.

Copy link
Owner Author

darkaxl commented Feb 27, 2018

Script en python, ganador del #SysArmyMx Challenge:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.