Last active
August 29, 2015 14:13
-
-
Save jolle-c/1ce7917c7668b71ae3c9 to your computer and use it in GitHub Desktop.
Command line script to move all newly added files from the original directory to a permanent storage directory and also create a DB record for each file moved
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
#!/usr/bin/lasso9 | |
database_initialize | |
local( | |
date = date, | |
tmp_filef = '//path/to/tmp_files/', | |
stored_filef = '//path/to/stored_files/', | |
path = #stored_filef + #date -> format(`yyyyMMddHHmmss`), | |
movetodir = dir(#path), | |
sql = "INSERT INTO database.table (filename, path, created_datetime) VALUES ", | |
sql_rows = array, | |
file | |
) | |
#movetodir -> create | |
with filename in file_listdirectory(#tmp_filef) | |
where not(#filename -> beginswith('.')) and not(#filename -> beginswith('_')) do { | |
#file = file(#tmp_filef + #filename) | |
#file -> moveto(#path + '/' + #filename) | |
#file -> close | |
stdoutnl(#filename) | |
#sql_rows -> insert("('" + #filename + "', '" + #path + "', '" + #date + "')") | |
} | |
inline( | |
-host =(: | |
-datasource ='mysqlds', | |
-name ='localhost', | |
-username ='myuser', | |
-password ='mypassword' | |
), | |
-sql = #sql + #sql_rows -> join(', ') | |
) => { | |
error_code ? stdoutnl(error_msg) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment