PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Trying to copy all *.csv files to another directory but fails -
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Trying to copy all *.csv files to another directory but fails -

Réponse
 
LinkBack Outils de la discussion
Vieux 24/08/2006, 17h42   #1
phillip.s.powell@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Trying to copy all *.csv files to another directory but fails -

# NOW WE COPY EVERYTHING OVER TO THE NEW FOLDERS IN $csvBackupPath
cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
cp -pr "$projectDocPath/*.csv" "$csvBackupPath/projectCSV"

This code I thought would simply copy everything ending in ".csv" to
another directory, but I get the following error:

No such file or directory *.csv

What must I do to ensure copying files over?

Thanx
Phil

  Réponse avec citation
Vieux 24/08/2006, 18h04   #2
Stephan 'smg' Grein
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trying to copy all *.csv files to another directory but fails-

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

phillip.s.powell@gmail.com wrote:
> # NOW WE COPY EVERYTHING OVER TO THE NEW FOLDERS IN $csvBackupPath
> cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
> cp -pr "$projectDocPath/*.csv" "$csvBackupPath/projectCSV"
>

Try that:
cd "$clientDocPath/" && for file in *.csv; do cp -p "$file"
"$csvBackupPath/clientCSV/${file}"; done
cd "$projectDocPath/" && for file in *.csv; do cp -p "$file"
"$csvBackupPath/projectCSV/${file}"; done

> This code I thought would simply copy everything ending in ".csv" to
> another directory, but I get the following error:
>
> No such file or directory *.csv

You got wrong with the * quantifier.
>
> What must I do to ensure copying files over?


try above
>
> Thanx
> Phil
>

np

- --
Stephan 'smg' Grein, <stephan at stephan minus rockt dot de>
https://stephangrein.de
GnuPG-Key-ID: 0xF8C275D4
FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iQIVAwUBRO3cJo1LAjD4wnXUAQLXAQ//azcZborYgbII4xSx7vHxDrIMTGSPyDdF
leKFQ2+ql1geK6L2vKfhbc84JlUU5EPp3EWXtsHc1jRAi65yzs H6ndKoogkSodRT
oaFy4v9AuAfzxmoYn0qluC6dgJkaKYySjH5GjPKd7n4anebB1e PVmg3TzDZPen07
9BvtNBd+FVBqf+RUPMp/C2uKoncFMb4Nr3aJG4aWj3SvK5O9kuw5CqUTPBQ6cz7j
Z5+LF6vA3vS85zr6hvAINuASyR/B9nTgioAxjUPiBIBuY13HuggDOMZImqayc4B0
iE0qPesW5n0F5WyrbV0MBDo09cugMvMCvzw/J0S7/gK2c97g959HG5pghnyMTE2W
jvQ0Ke7k/ojWZdhnNy+KSLRRzS2Ga9ZcDol8OWeldPmyWzkPsgsIRnD6aNH dDwey
pZxwlX0etjn4ff95IM6OLltXEgsXYmgkm9PuXEq+cO5aeAb7Jc y9fGz8myCz2mWC
ldSn8wfK57sJ8iMQdv2Twtndc06rOVRYUaSw5J1kcheRezqOjJ qy4YM8i4E8S5Qb
GvkJlXAAZm8PWHWdJKrW4Qlr80MZLisHevAgLtxbtclczkM7KE CGheGtWxQ+KuPE
6SWRlFh5N4rrZpwm18A53fUnn/D2Rt+zdhAK+ty48T3XeeIHipqkrZ7vSWAdbu/o
ya1Uhw9zJiU=
=VzzK
-----END PGP SIGNATURE-----
  Réponse avec citation
Vieux 24/08/2006, 18h10   #3
phillip.s.powell@gmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trying to copy all *.csv files to another directory but fails -


Stephan 'smg' Grein wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> phillip.s.powell@gmail.com wrote:
> > # NOW WE COPY EVERYTHING OVER TO THE NEW FOLDERS IN $csvBackupPath
> > cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
> > cp -pr "$projectDocPath/*.csv" "$csvBackupPath/projectCSV"
> >

> Try that:
> cd "$clientDocPath/" && for file in *.csv; do cp -p "$file"
> "$csvBackupPath/clientCSV/${file}"; done
> cd "$projectDocPath/" && for file in *.csv; do cp -p "$file"
> "$csvBackupPath/projectCSV/${file}"; done
>
> > This code I thought would simply copy everything ending in ".csv" to
> > another directory, but I get the following error:
> >
> > No such file or directory *.csv

> You got wrong with the * quantifier.
> >
> > What must I do to ensure copying files over?

>
> try above
> >
> > Thanx
> > Phil
> >

> np



Could you please explain that? None of it made sense to me, what is
that/??

Phil







>
> - --
> Stephan 'smg' Grein, <stephan at stephan minus rockt dot de>
> https://stephangrein.de
> GnuPG-Key-ID: 0xF8C275D4
> FingerPrint: 5B6F 134A 189B A24D 342B 0961 8D4B 0230 F8C2 75D4
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.5 (GNU/Linux)
>
> iQIVAwUBRO3cJo1LAjD4wnXUAQLXAQ//azcZborYgbII4xSx7vHxDrIMTGSPyDdF
> leKFQ2+ql1geK6L2vKfhbc84JlUU5EPp3EWXtsHc1jRAi65yzs H6ndKoogkSodRT
> oaFy4v9AuAfzxmoYn0qluC6dgJkaKYySjH5GjPKd7n4anebB1e PVmg3TzDZPen07
> 9BvtNBd+FVBqf+RUPMp/C2uKoncFMb4Nr3aJG4aWj3SvK5O9kuw5CqUTPBQ6cz7j
> Z5+LF6vA3vS85zr6hvAINuASyR/B9nTgioAxjUPiBIBuY13HuggDOMZImqayc4B0
> iE0qPesW5n0F5WyrbV0MBDo09cugMvMCvzw/J0S7/gK2c97g959HG5pghnyMTE2W
> jvQ0Ke7k/ojWZdhnNy+KSLRRzS2Ga9ZcDol8OWeldPmyWzkPsgsIRnD6aNH dDwey
> pZxwlX0etjn4ff95IM6OLltXEgsXYmgkm9PuXEq+cO5aeAb7Jc y9fGz8myCz2mWC
> ldSn8wfK57sJ8iMQdv2Twtndc06rOVRYUaSw5J1kcheRezqOjJ qy4YM8i4E8S5Qb
> GvkJlXAAZm8PWHWdJKrW4Qlr80MZLisHevAgLtxbtclczkM7KE CGheGtWxQ+KuPE
> 6SWRlFh5N4rrZpwm18A53fUnn/D2Rt+zdhAK+ty48T3XeeIHipqkrZ7vSWAdbu/o
> ya1Uhw9zJiU=
> =VzzK
> -----END PGP SIGNATURE-----


  Réponse avec citation
Vieux 24/08/2006, 19h55   #4
Xicheng Jia
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trying to copy all *.csv files to another directory but fails -

Stephan 'smg' Grein wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> phillip.s.powell@gmail.com wrote:
> > # NOW WE COPY EVERYTHING OVER TO THE NEW FOLDERS IN $csvBackupPath
> > cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
> > cp -pr "$projectDocPath/*.csv" "$csvBackupPath/projectCSV"
> >

> Try that:
> cd "$clientDocPath/" && for file in *.csv; do cp -p "$file"
> "$csvBackupPath/clientCSV/${file}"; done
> cd "$projectDocPath/" && for file in *.csv; do cp -p "$file"
> "$csvBackupPath/projectCSV/${file}"; done


you may get into trouble if "$projectDocPath" is not an absolute path.
to keep the current directory info, you may want to use sub-shell with
your commands, like

( cd "$clientDocPath/" && for file in *.csv; do cp -p "$file"
"$csvBackupPath/clientCSV/${file}"; done )

Also, using 'find' might save OP some typing:

find "$clientDocPath" -type f -name "*.csv"
-exec cp -p "{}" "$csvBackupPath/clientCSV/" \;

or use find | xargs, find -exec ... + .....

(untested)
Xicheng

  Réponse avec citation
Vieux 24/08/2006, 20h57   #5
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trying to copy all *.csv files to another directory but fails -

On 24 Aug 2006 10:10:52 -0700, phillip.s.powell@gmail.com
<phillip.s.powell@gmail.com> wrote:
>
> Stephan 'smg' Grein wrote:
>> -----BEGIN PGP SIGNED MESSAGE-----
>> Hash: SHA1
>>
>> phillip.s.powell@gmail.com wrote:
>> > # NOW WE COPY EVERYTHING OVER TO THE NEW FOLDERS IN $csvBackupPath
>> > cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
>> > cp -pr "$projectDocPath/*.csv" "$csvBackupPath/projectCSV"
>> >

>> Try that:
>> cd "$clientDocPath/" && for file in *.csv; do cp -p "$file"
>> "$csvBackupPath/clientCSV/${file}"; done
>> cd "$projectDocPath/" && for file in *.csv; do cp -p "$file"
>> "$csvBackupPath/projectCSV/${file}"; done
>>
>> > This code I thought would simply copy everything ending in ".csv" to
>> > another directory, but I get the following error:
>> >
>> > No such file or directory *.csv

>> You got wrong with the * quantifier.
>> >
>> > What must I do to ensure copying files over?

>>
>> try above
>> >
>> > Thanx
>> > Phil
>> >

>> np

>
>
> Could you please explain that? None of it made sense to me, what is
> that/??
>
> Phil
>

In sh and similar shells, if there is no file matching a wildcard
expression, the wildcard expression is left as is on the command
line. To avoid an error, you can use

if [ -f "$clientDocPath/*.csv" ]; then
cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
fi


--
Truth is the most valuable thing we have -- so let us economize it.
-- Mark Twain
  Réponse avec citation
Vieux 25/08/2006, 00h14   #6
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trying to copy all *.csv files to another directory but fails -

On 2006-08-24, phillip.s.powell@gmail.com wrote:
> # NOW WE COPY EVERYTHING OVER TO THE NEW FOLDERS IN $csvBackupPath
> cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
> cp -pr "$projectDocPath/*.csv" "$csvBackupPath/projectCSV"
>
> This code I thought would simply copy everything ending in ".csv" to
> another directory, but I get the following error:
>
> No such file or directory *.csv


Filenames are not expanded inside quotes:

cp -pr "$clientDocPath/"*.csv "$csvBackupPath/clientCSV"
cp -pr "$projectDocPath/"*.csv "$csvBackupPath/projectCSV"

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Vieux 25/08/2006, 08h24   #7
Chris F.A. Johnson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trying to copy all *.csv files to another directory but fails -

On 2006-08-24, Bill Marcum wrote:
> On 24 Aug 2006 10:10:52 -0700, phillip.s.powell@gmail.com
> <phillip.s.powell@gmail.com> wrote:
>>
>> Stephan 'smg' Grein wrote:
>>> -----BEGIN PGP SIGNED MESSAGE-----
>>> Hash: SHA1
>>>
>>> phillip.s.powell@gmail.com wrote:
>>> > # NOW WE COPY EVERYTHING OVER TO THE NEW FOLDERS IN $csvBackupPath
>>> > cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
>>> > cp -pr "$projectDocPath/*.csv" "$csvBackupPath/projectCSV"
>>> >
>>> Try that:
>>> cd "$clientDocPath/" && for file in *.csv; do cp -p "$file"
>>> "$csvBackupPath/clientCSV/${file}"; done
>>> cd "$projectDocPath/" && for file in *.csv; do cp -p "$file"
>>> "$csvBackupPath/projectCSV/${file}"; done
>>>
>>> > This code I thought would simply copy everything ending in ".csv" to
>>> > another directory, but I get the following error:
>>> >
>>> > No such file or directory *.csv
>>> You got wrong with the * quantifier.
>>> >
>>> > What must I do to ensure copying files over?
>>>
>>> try above

>>
>> Could you please explain that? None of it made sense to me, what is
>> that/??
>>

> In sh and similar shells, if there is no file matching a wildcard
> expression, the wildcard expression is left as is on the command
> line. To avoid an error, you can use
>
> if [ -f "$clientDocPath/*.csv" ]; then


That doesn't work, because the wildcard will not be expanded.

> cp -pr "$clientDocPath/*.csv" "$csvBackupPath/clientCSV"
> fi
>
>



--
Chris F.A. Johnson, author <http://cfaj.freeshell.org>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h50.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18364 seconds with 15 queries