* add folder name to filename
@ 2006-09-14 12:23 Nikolaos A. Patsopoulos
2006-09-14 12:30 ` Eric Blake
0 siblings, 1 reply; 8+ messages in thread
From: Nikolaos A. Patsopoulos @ 2006-09-14 12:23 UTC (permalink / raw)
To: cygwin
Hi,
I have
the following structure of folders and files:
..
folder1
file1
file2
folder2
file1
file2
.....
and want to add the folder name into the filename:
folder1
folder1_file1
folder1_file2
folder2
folder2_file1
folder2_file2
I used the following script but doesn't work under cygwin:
for file in folder*/*; do
dir=$(basename $(dirname $file) )
base=$(basename $file)
mv $file $(dirname $file)/${dir}_${base}
done
Does anyone has a suggestion or where I should look?
Thanks in advance,
Nikos
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: add folder name to filename
2006-09-14 12:23 add folder name to filename Nikolaos A. Patsopoulos
@ 2006-09-14 12:30 ` Eric Blake
2006-09-14 12:35 ` Nikolaos A. Patsopoulos
0 siblings, 1 reply; 8+ messages in thread
From: Eric Blake @ 2006-09-14 12:30 UTC (permalink / raw)
To: cygwin, npatsop
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Nikolaos A. Patsopoulos on 9/14/2006 6:23 AM:
>
> I used the following script but doesn't work under cygwin:
>
> for file in folder*/*; do
> dir=$(basename $(dirname $file) )
> base=$(basename $file)
> mv $file $(dirname $file)/${dir}_${base}
> done
What is the actual error message you are seeing? But I bet the problem is
due to your missing quoting, so your problem is not cygwin-specific. I
would guess that you are having issues due to spaces or other shell
metacharacters in the filenames being interpreted literally.
>
> Does anyone has a suggestion or where I should look?
A good tutorial on shell programming? Hint:
for file in folder*/*; do
dir=$(basename "$(dirname "$file")")
base=$(basename "$file")
mv "$file" "$(dirname "$file")/${dir}_${base}"
done
(That won't work on filenames with \n as the last character, but
fortunately, unless you use cygwin managed mounts, that is not an issue on
cygwin).
- --
Life is short - so eat dessert first!
Eric Blake ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFCUuD84KuGfSFAYARAn1BAJ41A85ZHvKBAWtKa3tWKO+4fLrh5gCgkw+j
fzK7C9kby5r6M26SQQk2pvo=
=CZVE
-----END PGP SIGNATURE-----
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: add folder name to filename
2006-09-14 12:30 ` Eric Blake
@ 2006-09-14 12:35 ` Nikolaos A. Patsopoulos
2006-09-14 12:43 ` Eric Blake
0 siblings, 1 reply; 8+ messages in thread
From: Nikolaos A. Patsopoulos @ 2006-09-14 12:35 UTC (permalink / raw)
To: Eric Blake; +Cc: cygwin
Eric Blake wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> According to Nikolaos A. Patsopoulos on 9/14/2006 6:23 AM:
>
>> I used the following script but doesn't work under cygwin:
>>
>> for file in folder*/*; do
>> dir=$(basename $(dirname $file) )
>> base=$(basename $file)
>> mv $file $(dirname $file)/${dir}_${base}
>> done
>>
>
> What is the actual error message you are seeing? But I bet the problem is
> due to your missing quoting, so your problem is not cygwin-specific. I
> would guess that you are having issues due to spaces or other shell
> metacharacters in the filenames being interpreted literally.
>
>
>> Does anyone has a suggestion or where I should look?
>>
>
> A good tutorial on shell programming? Hint:
>
> for file in folder*/*; do
> dir=$(basename "$(dirname "$file")")
> base=$(basename "$file")
> mv "$file" "$(dirname "$file")/${dir}_${base}"
> done
>
> (That won't work on filenames with \n as the last character, but
> fortunately, unless you use cygwin managed mounts, that is not an issue on
> cygwin).
>
> - --
> Life is short - so eat dessert first!
>
> Eric Blake ebb9@byu.net
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.1 (Cygwin)
> Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFFCUuD84KuGfSFAYARAn1BAJ41A85ZHvKBAWtKa3tWKO+4fLrh5gCgkw+j
> fzK7C9kby5r6M26SQQk2pvo=
> =CZVE
> -----END PGP SIGNATURE-----
>
>
>
I get the same error with my code and yours:
Script started, file is typescript
nothing happens, except an empty file called typescript in the parent
directory
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: add folder name to filename
2006-09-14 12:35 ` Nikolaos A. Patsopoulos
@ 2006-09-14 12:43 ` Eric Blake
2006-09-14 12:53 ` Nikolaos A. Patsopoulos
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Eric Blake @ 2006-09-14 12:43 UTC (permalink / raw)
To: cygwin, npatsop
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Nikolaos A. Patsopoulos on 9/14/2006 6:35 AM:
> I get the same error with my code and yours:
> Script started, file is typescript
> nothing happens, except an empty file called typescript in the parent
> directory
We actually need to see a reproducible test case, complete with ACTUAL
error messages from the console, not a description of what happened.
Otherwise we don't know what went wrong to try to help.
Reread this link:
> Problem reports: http://cygwin.com/problems.html
You could also try 'echo folder*/*' to see what files are being visited in
the for loop, or even download the bashdb package using setup.exe and use
the bash debugger to single step through the loop to try to spot your
error. But this is working just fine for me, so you will have to try
harder before I will be convinced that this is a cygwin-specific bug.
- --
Life is short - so eat dessert first!
Eric Blake ebb9@byu.net
volunteer cygwin bash/bashdb maintainer
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.1 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFCU6J84KuGfSFAYARAhp/AKCFI9mWV74UxM7IWi+OHmfFPGk08ACcCPkB
IUrvHBN/xzzYWeL/8pVjV74=
=ZRwy
-----END PGP SIGNATURE-----
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: add folder name to filename
2006-09-14 12:43 ` Eric Blake
@ 2006-09-14 12:53 ` Nikolaos A. Patsopoulos
2006-09-14 13:03 ` Nikolaos A. Patsopoulos
2006-09-14 13:09 ` Nikolaos A. Patsopoulos
2 siblings, 0 replies; 8+ messages in thread
From: Nikolaos A. Patsopoulos @ 2006-09-14 12:53 UTC (permalink / raw)
To: Eric Blake; +Cc: cygwin
Eric Blake wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> According to Nikolaos A. Patsopoulos on 9/14/2006 6:35 AM:
>
>
>> I get the same error with my code and yours:
>>
>
>
>> Script started, file is typescript
>>
>
>
>> nothing happens, except an empty file called typescript in the parent
>> directory
>>
>
> We actually need to see a reproducible test case, complete with ACTUAL
> error messages from the console, not a description of what happened.
> Otherwise we don't know what went wrong to try to help.
>
> Reread this link:
>
>> Problem reports: http://cygwin.com/problems.html
>>
>
> You could also try 'echo folder*/*' to see what files are being visited in
> the for loop, or even download the bashdb package using setup.exe and use
> the bash debugger to single step through the loop to try to spot your
> error. But this is working just fine for me, so you will have to try
> harder before I will be convinced that this is a cygwin-specific bug.
>
> - --
> Life is short - so eat dessert first!
>
> Eric Blake ebb9@byu.net
> volunteer cygwin bash/bashdb maintainer
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.1 (Cygwin)
> Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFFCU6J84KuGfSFAYARAhp/AKCFI9mWV74UxM7IWi+OHmfFPGk08ACcCPkB
> IUrvHBN/xzzYWeL/8pVjV74=
> =ZRwy
> -----END PGP SIGNATURE-----
>
>
>
>We actually need to see a reproducible test case, complete with ACTUAL
>error messages from the console, not a description of what happened.
>Otherwise we don't know what went wrong to try to help.
I don't know what to you mean by "ACTUAL" but I think of actual whatever returns on bash command line and that is:
Script started, file is typescript
adding an ECHO command has the same result. I'm not sure that's a Cugwin
related problem but I have to start from somewhere to figure out what is
going on.
thanks
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: add folder name to filename
2006-09-14 12:43 ` Eric Blake
2006-09-14 12:53 ` Nikolaos A. Patsopoulos
@ 2006-09-14 13:03 ` Nikolaos A. Patsopoulos
2006-09-14 13:09 ` Nikolaos A. Patsopoulos
2 siblings, 0 replies; 8+ messages in thread
From: Nikolaos A. Patsopoulos @ 2006-09-14 13:03 UTC (permalink / raw)
To: Eric Blake; +Cc: cygwin
Eric Blake wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> According to Nikolaos A. Patsopoulos on 9/14/2006 6:35 AM:
>
>
>> I get the same error with my code and yours:
>>
>
>
>> Script started, file is typescript
>>
>
>
>> nothing happens, except an empty file called typescript in the parent
>> directory
>>
>
> We actually need to see a reproducible test case, complete with ACTUAL
> error messages from the console, not a description of what happened.
> Otherwise we don't know what went wrong to try to help.
>
> Reread this link:
>
>> Problem reports: http://cygwin.com/problems.html
>>
>
> You could also try 'echo folder*/*' to see what files are being visited in
> the for loop, or even download the bashdb package using setup.exe and use
> the bash debugger to single step through the loop to try to spot your
> error. But this is working just fine for me, so you will have to try
> harder before I will be convinced that this is a cygwin-specific bug.
>
> - --
> Life is short - so eat dessert first!
>
> Eric Blake ebb9@byu.net
> volunteer cygwin bash/bashdb maintainer
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.1 (Cygwin)
> Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFFCU6J84KuGfSFAYARAhp/AKCFI9mWV74UxM7IWi+OHmfFPGk08ACcCPkB
> IUrvHBN/xzzYWeL/8pVjV74=
> =ZRwy
> -----END PGP SIGNATURE-----
>
>
>
Well you were right.............
here is the error message:
folder*/* #this is the echo command
mv: cannot stat 'folder*/*': No such file or directory
--
Nikolaos A. Patsopoulos, MD
Department of Hygiene and Epidemiology
University of Ioannina School of Medicine
University Campus
Ioannina 45110
Greece
Tel: (+30) 26510-97804
mobile: +30 6972882016
Fax: (+30) 26510-97867 (care of Nikolaos A. Patsopoulos)
e-mail: npatsop@cc.uoi.gr
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: add folder name to filename
2006-09-14 12:43 ` Eric Blake
2006-09-14 12:53 ` Nikolaos A. Patsopoulos
2006-09-14 13:03 ` Nikolaos A. Patsopoulos
@ 2006-09-14 13:09 ` Nikolaos A. Patsopoulos
2006-09-16 12:35 ` Re[2]: " oleyk
2 siblings, 1 reply; 8+ messages in thread
From: Nikolaos A. Patsopoulos @ 2006-09-14 13:09 UTC (permalink / raw)
To: Eric Blake; +Cc: cygwin
Eric Blake wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> According to Nikolaos A. Patsopoulos on 9/14/2006 6:35 AM:
>
>
>> I get the same error with my code and yours:
>>
>
>
>> Script started, file is typescript
>>
>
>
>> nothing happens, except an empty file called typescript in the parent
>> directory
>>
>
> We actually need to see a reproducible test case, complete with ACTUAL
> error messages from the console, not a description of what happened.
> Otherwise we don't know what went wrong to try to help.
>
> Reread this link:
>
>> Problem reports: http://cygwin.com/problems.html
>>
>
> You could also try 'echo folder*/*' to see what files are being visited in
> the for loop, or even download the bashdb package using setup.exe and use
> the bash debugger to single step through the loop to try to spot your
> error. But this is working just fine for me, so you will have to try
> harder before I will be convinced that this is a cygwin-specific bug.
>
> - --
> Life is short - so eat dessert first!
>
> Eric Blake ebb9@byu.net
> volunteer cygwin bash/bashdb maintainer
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.2.1 (Cygwin)
> Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
>
> iD8DBQFFCU6J84KuGfSFAYARAhp/AKCFI9mWV74UxM7IWi+OHmfFPGk08ACcCPkB
> IUrvHBN/xzzYWeL/8pVjV74=
> =ZRwy
> -----END PGP SIGNATURE-----
>
>
>
Fixed :
added a space after "folder":
for file in folder */*; do
echo folder */*
dir=$(basename "$(dirname "$file")")
base=$(basename "$file")
mv "$file" "$(dirname "$file")/${dir}_${base}"
done
Thanks a lot Eric!
Nikos
--
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html
Documentation: http://cygwin.com/docs.html
FAQ: http://cygwin.com/faq/
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-09-16 12:35 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-14 12:23 add folder name to filename Nikolaos A. Patsopoulos
2006-09-14 12:30 ` Eric Blake
2006-09-14 12:35 ` Nikolaos A. Patsopoulos
2006-09-14 12:43 ` Eric Blake
2006-09-14 12:53 ` Nikolaos A. Patsopoulos
2006-09-14 13:03 ` Nikolaos A. Patsopoulos
2006-09-14 13:09 ` Nikolaos A. Patsopoulos
2006-09-16 12:35 ` Re[2]: " oleyk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).