-
Notifications
You must be signed in to change notification settings - Fork 2
/
Mkdir.sh
executable file
·30 lines (24 loc) · 879 Bytes
/
Mkdir.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# Specify the directory where your files are located
sourceDirectory="/home/tusharbhatia/pyq-20240228T141016Z-001/pyq/2018-19/All"
# Get all files in the source directory
IFS=$'\n' # Set internal field separator to newline to handle filenames with spaces correctly
files=$(find "$sourceDirectory" -type f -name "*.pdf")
# Initialize counter
counter=1
# Iterate through each file
for file in $files; do
# Check if the file exists
if [ -f "$file" ]; then
# Create a directory with sequential numbering
directoryName="$sourceDirectory/$counter"
mkdir -p "$directoryName"
# Move the file to the newly created directory
mv "$file" "$directoryName"
echo "Moved $file to $directoryName"
# Increment counter
((counter++))
else
echo "File $file not found or inaccessible."
fi
done