You are not logged in.

#1 2011-01-28 16:32:37

mandorory
Member
Registered: 2010-12-27
Posts: 16

Create folders from text file

can anyone show me how to create directories from a text file.
each line = 1 folder

name
name lastname
and so on...


thanks in advance

Offline

#2 2011-01-28 16:37:12

SS4
Member
From: !Rochford, Essex
Registered: 2010-12-05
Posts: 699

Re: Create folders from text file

For ones without spaces you can use

mkdir -p $(cat file)

edit 1: if the paths aren't absolute it will be better to cd into the directory you want to create them in

Last edited by SS4 (2011-01-28 16:37:59)


Rauchen verboten

Offline

#3 2011-01-28 16:46:20

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Create folders from text file

#!/bin/bash
IFS='
'
for _dir in $(cat "$1"); do
  mkdir "$_dir"
done

Invoke it with the path to the text file.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#4 2011-01-28 16:48:11

mandorory
Member
Registered: 2010-12-27
Posts: 16

Re: Create folders from text file

Thanks a lot that was fast.

i was trying to get this command to work but it kept putting ? and spaces at the end of the name

while read line; do mkdir -v "$line"; done < test.txt

how would i fix that?

Offline

#5 2011-01-28 16:53:03

mandorory
Member
Registered: 2010-12-27
Posts: 16

Re: Create folders from text file

Xyne wrote:
#!/bin/bash
IFS='
'
for _dir in $(cat "$1"); do
  mkdir "$_dir"
done

Invoke it with the path to the text file.

I tried that but it still put "?" at the end of the name
some of the names have up to 30 characters in length

Offline

#6 2011-01-28 16:56:24

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Create folders from text file

Both that, and your "read" loop work for me. Maybe there's something wrong with the encoding of your file.

Can you post the test.txt file that you're using so that I can test it?

Last edited by Xyne (2011-01-28 16:56:54)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#7 2011-01-28 17:09:57

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,576

Re: Create folders from text file

Perhaps your input file has msdos style line terminators ie \r\n

Offline

#8 2011-01-28 18:00:28

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Create folders from text file

skunktrader wrote:

Perhaps your input file has msdos style line terminators ie \r\n

That's what I'm thinking.


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#9 2011-01-28 18:48:45

mandorory
Member
Registered: 2010-12-27
Posts: 16

Re: Create folders from text file

Xyne wrote:
skunktrader wrote:

Perhaps your input file has msdos style line terminators ie \r\n

That's what I'm thinking.

well it was created in notepad and the list was copied from a Excel sheet, how would i go about removing that?

Offline

#10 2011-01-28 19:56:04

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,965
Website

Re: Create folders from text file


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#11 2011-01-28 20:33:48

mandorory
Member
Registered: 2010-12-27
Posts: 16

Re: Create folders from text file

Thanks

Offline

#12 2011-01-28 21:26:18

mandorory
Member
Registered: 2010-12-27
Posts: 16

Re: Create folders from text file

One more question, I got the folders created now, but when i access it from a windows computer through the network the name of the folder goes from

Name Of Company 1

to

NFSDGF2~1

but on Linux it doesn't.

im using samba shares

Offline

Board footer

Powered by FluxBB