0

I have written a small batch script which copies files from the a folder and paste in other folder with delay of 10 seconds. I want to convert it to shell script, but not getting the way to do that. Please help me. The below is the batch script that i use:

@echo off & setLocal EnableDELAYedExpansion

pushd "C:\Users\abc\Desktop\Test"
for /f "tokens=*" %%a in ('dir /b/a-d "leaderboard*.txt"') do (
copy "%%a" "C:\Users\abc\Desktop\Test\final\leaderboard.txt"
timeout 10
) 
popd 

1 Answer 1

1

Set the sourcedir and targetdir to the one you want (not according to your code you always copy on the same file leaderboard.txt, if you want to keep the original name just remove "leaderboard.txt" and keep only "$targetdir"

sourcedir=<SOURCEDIR>
targetdir=<TARGETDIR>

for a in "$sourcedir"/leaderboard*.txt; do
    cp "$a" "$targetdir"/leaderboard.txt
    sleep 10
done

NB: This solution does not work if you have spaces in the name of the files you want to copy

Sign up to request clarification or add additional context in comments.

1 Comment

This should work fine for filenames with spaces, as long as you keep quoting $a, $sourcedir, and $targetdir. Word-splitting takes place prior to pathname expansion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.