Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as Bash by awdawd ( 3 years ago )
#!/bin/bash

# Ask for 'from' directory
echo "Enter 'from' directory path:"
read from_dir

# Ask for 'to' directory
echo "Enter 'to' directory path:"
read to_dir

# Ask for pattern
echo "Enter pattern:"
read pattern

# Initialize counter
count=0

# Initialize list of copied files
copied_files=""

# Iterate over files in 'from' directory
for file in "$from_dir"/*; do
  # Check if file name contains pattern
  if [[ $(basename "$file") == *"$pattern"* ]]; then
    # Move file to 'to' directory
    mv "$file" "$to_dir"
    # Increment counter
    ((count++))
    # Add file to list of copied files
    copied_files+=$(basename "$file")", "
  fi
done

# Remove trailing comma and space from list of copied files
copied_files=${copied_files%??}

# Print result
echo "Copied $count files with pattern '$pattern': $copied_files to folder: $to_dir"

 

Revise this Paste

Your Name: Code Language: