Skip to content

Instantly share code, notes, and snippets.

@jolle-c
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jolle-c/1ce7917c7668b71ae3c9 to your computer and use it in GitHub Desktop.
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
#!/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