7 added 2 characters in body
source | link

In a directory I have files with the names:

01.txt 02.txt 03.txt

In the same directory are folders with the names:

01.abc 02.def 03.ghi

I need a command to copy the files to the folders one by one, so that 01.txt is in 01.abc, 02.txt is in 02.def and 03.txt is in 03.ghi. The command should not consider the names of the folders but fill the folders with the files top down (one file to each folder).

Many thanks!

Edit 1:

I have changed the code from Move files to multiple folders [closed] as follows: #!/bin/bash

#!/bin/bash

LISTFILESCMD='ls *.txt' 
FQUANTITY=1
FOLDERLIST=`seq -w 1 3`

for FOLDER in $FOLDERLIST; do mv `$LISTFILESCMD | head -n $FQUANTITY`   $FOLDER; done

The result is, that the 3 files are in the 3rd folder.

Edit 2:

No, with FQUANTITY=3 the files go in the 1st folder.

With FQUANTITY=1 the script above works. But it doesn't work right, if the filenames or the foldernames contain spaces.

I have made a second script, which also works with spaces in filenames, but only if the filenames contain a dot, and this script doesn't work, if the foldernames contain spaces. I would like to know, how to make it work also with spaces in foldernames and/or without dots in filenames:

#!/bin/bash

array1=(*/) # folder
array2=(*.*) # file

for ((i=0;i<${#array2[@]};++i)); do
    mv "${array2[i]}" "${array1[i]}"
done

Thanks!

In a directory I have files with the names:

01.txt 02.txt 03.txt

In the same directory are folders with the names:

01.abc 02.def 03.ghi

I need a command to copy the files to the folders one by one, so that 01.txt is in 01.abc, 02.txt is in 02.def and 03.txt is in 03.ghi. The command should not consider the names of the folders but fill the folders with the files top down (one file to each folder).

Many thanks!

Edit 1:

I have changed the code from Move files to multiple folders [closed] as follows: #!/bin/bash

LISTFILESCMD='ls *.txt' 
FQUANTITY=1
FOLDERLIST=`seq -w 1 3`

for FOLDER in $FOLDERLIST; do mv `$LISTFILESCMD | head -n $FQUANTITY`   $FOLDER; done

The result is, that the 3 files are in the 3rd folder.

Edit 2:

No, with FQUANTITY=3 the files go in the 1st folder.

With FQUANTITY=1 the script above works. But it doesn't work right, if the filenames or the foldernames contain spaces.

I have made a second script, which also works with spaces in filenames, but only if the filenames contain a dot, and this script doesn't work, if the foldernames contain spaces. I would like to know, how to make it work also with spaces in foldernames and/or without dots in filenames:

#!/bin/bash

array1=(*/) # folder
array2=(*.*) # file

for ((i=0;i<${#array2[@]};++i)); do
    mv "${array2[i]}" "${array1[i]}"
done

Thanks!

In a directory I have files with the names:

01.txt 02.txt 03.txt

In the same directory are folders with the names:

01.abc 02.def 03.ghi

I need a command to copy the files to the folders one by one, so that 01.txt is in 01.abc, 02.txt is in 02.def and 03.txt is in 03.ghi. The command should not consider the names of the folders but fill the folders with the files top down (one file to each folder).

Many thanks!

Edit 1:

I have changed the code from Move files to multiple folders [closed] as follows:

#!/bin/bash

LISTFILESCMD='ls *.txt' 
FQUANTITY=1
FOLDERLIST=`seq -w 1 3`

for FOLDER in $FOLDERLIST; do mv `$LISTFILESCMD | head -n $FQUANTITY`   $FOLDER; done

The result is, that the 3 files are in the 3rd folder.

Edit 2:

No, with FQUANTITY=3 the files go in the 1st folder.

With FQUANTITY=1 the script above works. But it doesn't work right, if the filenames or the foldernames contain spaces.

I have made a second script, which also works with spaces in filenames, but only if the filenames contain a dot, and this script doesn't work, if the foldernames contain spaces. I would like to know, how to make it work also with spaces in foldernames and/or without dots in filenames:

#!/bin/bash

array1=(*/) # folder
array2=(*.*) # file

for ((i=0;i<${#array2[@]};++i)); do
    mv "${array2[i]}" "${array1[i]}"
done

Thanks!

6 added 683 characters in body
source | link

In a directory I have files with the names:

01.txt 02.txt 03.txt

In the same directory are folders with the names:

01.abc 02.def 03.ghi

I need a command to copy the files to the folders one by one, so that 01.txt is in 01.abc, 02.txt is in 02.def and 03.txt is in 03.ghi. The command should not consider the names of the folders but fill the folders with the files top down (one file to each folder).

Many thanks!

Edit 1:

I have changed the code from Move files to multiple folders [closed] as follows: #!/bin/bash

LISTFILESCMD='ls *.txt' 
FQUANTITY=1
FOLDERLIST=`seq -w 1 3`

for FOLDER in $FOLDERLIST; do mv `$LISTFILESCMD | head -n $FQUANTITY`   $FOLDER; done

The result is, that the 3 files are in the 3rd folder.

Edit 2: No

No, with FQUANTITY=3 the files go in the 1st folder.

With FQUANTITY=1 the script above works. But it doesn't work right, if the filenames or the foldernames contain spaces.

I have made a second script, which also works with spaces in filenames, but only if the filnamesfilenames contain a dot, and this script doesn't work, if the foldernames contain spaces. I would like to know, how to make it work also with spaces in foldernames and/or without dotdots in filenames:

#!/bin/bash

array1=(*/) # folder
array2=(*.*) # file

for ((i=0;i<${#array2[@]};++i)); do
    mv "${array2[i]}" "${array1[i]}"
done

Thanks!

In a directory I have files with the names:

01.txt 02.txt 03.txt

In the same directory are folders with the names:

01.abc 02.def 03.ghi

I need a command to copy the files to the folders one by one, so that 01.txt is in 01.abc, 02.txt is in 02.def and 03.txt is in 03.ghi. The command should not consider the names of the folders but fill the folders with the files top down (one file to each folder).

Many thanks!

Edit 1:

I have changed the code from Move files to multiple folders [closed] as follows: #!/bin/bash

LISTFILESCMD='ls *.txt' 
FQUANTITY=1
FOLDERLIST=`seq -w 1 3`

for FOLDER in $FOLDERLIST; do mv `$LISTFILESCMD | head -n $FQUANTITY`   $FOLDER; done

The result is, that the 3 files are in the 3rd folder.

Edit 2: No, with FQUANTITY=3 the files go in the 1st folder.

With FQUANTITY=1 the script above works. But it doesn't work right, if the filenames or the foldernames contain spaces.

I have made a second script, which also works with spaces in filenames, but only if the filnames contain a dot, and this script doesn't work, if the foldernames contain spaces. I would like to know, how to make it work also with spaces in foldernames and/or without dot in filenames:

#!/bin/bash

array1=(*/) # folder
array2=(*.*) # file

for ((i=0;i<${#array2[@]};++i)); do
    mv "${array2[i]}" "${array1[i]}"
done

Thanks!

In a directory I have files with the names:

01.txt 02.txt 03.txt

In the same directory are folders with the names:

01.abc 02.def 03.ghi

I need a command to copy the files to the folders one by one, so that 01.txt is in 01.abc, 02.txt is in 02.def and 03.txt is in 03.ghi. The command should not consider the names of the folders but fill the folders with the files top down (one file to each folder).

Many thanks!

Edit 1:

I have changed the code from Move files to multiple folders [closed] as follows: #!/bin/bash

LISTFILESCMD='ls *.txt' 
FQUANTITY=1
FOLDERLIST=`seq -w 1 3`

for FOLDER in $FOLDERLIST; do mv `$LISTFILESCMD | head -n $FQUANTITY`   $FOLDER; done

The result is, that the 3 files are in the 3rd folder.

Edit 2:

No, with FQUANTITY=3 the files go in the 1st folder.

With FQUANTITY=1 the script above works. But it doesn't work right, if the filenames or the foldernames contain spaces.

I have made a second script, which also works with spaces in filenames, but only if the filenames contain a dot, and this script doesn't work, if the foldernames contain spaces. I would like to know, how to make it work also with spaces in foldernames and/or without dots in filenames:

#!/bin/bash

array1=(*/) # folder
array2=(*.*) # file

for ((i=0;i<${#array2[@]};++i)); do
    mv "${array2[i]}" "${array1[i]}"
done

Thanks!

5 added 683 characters in body
source | link

In a directory I have files with the names:

01.txt 02.txt 03.txt

In the same directory are folders with the names:

01.abc 02.def 03.ghi

I need a command to copy the files to the folders one by one, so that 01.txt is in 01.abc, 02.txt is in 02.def and 03.txt is in 03.ghi. The command should not consider the names of the folders but fill the folders with the files top down (one file to each folder).

Many thanks!

Edit 1:

I have changed the code from Move files to multiple folders [closed] as follows: #!/bin/bash

LISTFILESCMD='ls *.txt' 
FQUANTITY=3FQUANTITY=1
FOLDERLIST=`seq -w 1 3`

for FOLDER in $FOLDERLIST; do mv `$LISTFILESCMD | head -n $FQUANTITY`   $FOLDER; done

The result is, that the 3 files are in the 3rd folder.

Edit 2: No, with FQUANTITY=3 the files go in the 1st folder.

With FQUANTITY=1 the script above works. But it doesn't work right, if the filenames or the foldernames contain spaces.

I have made a second script, which also works with spaces in filenames, but only if the filnames contain a dot, and this script doesn't work, if the foldernames contain spaces. I would like to know, how to make it work also with spaces in foldernames and/or without dot in filenames:

#!/bin/bash

array1=(*/) # folder
array2=(*.*) # file

for ((i=0;i<${#array2[@]};++i)); do
    mv "${array2[i]}" "${array1[i]}"
done

Thanks!

In a directory I have files with the names:

01.txt 02.txt 03.txt

In the same directory are folders with the names:

01.abc 02.def 03.ghi

I need a command to copy the files to the folders one by one, so that 01.txt is in 01.abc, 02.txt is in 02.def and 03.txt is in 03.ghi. The command should not consider the names of the folders but fill the folders with the files top down (one file to each folder).

Many thanks!

Edit:

I have changed the code from Move files to multiple folders [closed] as follows:

LISTFILESCMD='ls *.txt' 
FQUANTITY=3
FOLDERLIST=`seq -w 1 3`

for FOLDER in $FOLDERLIST; do mv `$LISTFILESCMD | head -n $FQUANTITY`   $FOLDER; done

The result is, that the 3 files are in the 3rd folder.

In a directory I have files with the names:

01.txt 02.txt 03.txt

In the same directory are folders with the names:

01.abc 02.def 03.ghi

I need a command to copy the files to the folders one by one, so that 01.txt is in 01.abc, 02.txt is in 02.def and 03.txt is in 03.ghi. The command should not consider the names of the folders but fill the folders with the files top down (one file to each folder).

Many thanks!

Edit 1:

I have changed the code from Move files to multiple folders [closed] as follows: #!/bin/bash

LISTFILESCMD='ls *.txt' 
FQUANTITY=1
FOLDERLIST=`seq -w 1 3`

for FOLDER in $FOLDERLIST; do mv `$LISTFILESCMD | head -n $FQUANTITY`   $FOLDER; done

The result is, that the 3 files are in the 3rd folder.

Edit 2: No, with FQUANTITY=3 the files go in the 1st folder.

With FQUANTITY=1 the script above works. But it doesn't work right, if the filenames or the foldernames contain spaces.

I have made a second script, which also works with spaces in filenames, but only if the filnames contain a dot, and this script doesn't work, if the foldernames contain spaces. I would like to know, how to make it work also with spaces in foldernames and/or without dot in filenames:

#!/bin/bash

array1=(*/) # folder
array2=(*.*) # file

for ((i=0;i<${#array2[@]};++i)); do
    mv "${array2[i]}" "${array1[i]}"
done

Thanks!

4 added 2 characters in body
source | link
3 added 367 characters in body
source | link
2 edited tags
| link
1
source | link