Created
February 27, 2018 04:27
-
-
Save AlexCallejas/18006491df9408295031ed134dd9c343 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Script en python, ganador del #SysArmyMx Challenge:
http://www.rootzilopochtli.com/2018/02/sysarmymx-challenge/