The program saves files in its own directory. How can I tell it to save all output files in an existing subdirectory "data"? Or even better, check the existence of a subdirectory "data", create "data" if it does not exist, and tell the program to save there.

The program saves files in its own directory. How can I tell it to save all output files in an existing subdirectory "data"? Or even better, check the existence of a subdirectory "data", create "data" if it does not exist, and tell the program to save there.

It seems like your telling him it can't be done... it can.

# If a sub directory named "data" doesn't exist, if it doesn't create it

Code:

if [ ! -d "data" ]; then mkdir datafi

# Tell the program to save there ...

Method one# The simplest method would be to move (mv) them after they are created# Say they all had the extention .final ...then

Maybe not extremely pretty, perhaps not perfect.....but it works.The only thing that you may have to take into account with the second method, is if your "finalism" program is getting data from the original directory

However, there is not only ONE way to do things .... if that were the case, we'd all be programming in python... perhaps why I prefer perl over python myself, but like bash the best still.

So, for me, instead of creating a tempfile that is used only for timestamp comparisons in a dir that others can see, with mktemp, I'd just use touch with a hidden timestamp file for comparisons in the same directory.

Code:

# Create a temp file that's sole purpose is used for timestamp comparison purposes.# IE: when comparing the timestamp of this file agains all others, you will be able to see which files # were created AFTER this one...and determine if they should be moved to the data filetouch .mytimestamp

# Compare all files in the current dir to .mytimestamp.# if the creation time of any of the files are newer than .mytimestamp# move those files to /data dir.for f in ./*; do if [ -f "$f" ] && [ "$f" -nt ".mytimestamp" ]; then mv "$f" data/ fi done

# Remove the hidden file we created for timestamp purposesrm .mytimestamp

I did like the use of comparing the timestamp to determine if the file should be moved, excellent idea, I had not thought of that option.

Who is online

Users browsing this forum: Google [Bot] and 13 guests

You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum