File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Linux / UNIX and the fly likes how to copy a file to a different location with a part of the file name as the filename Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "how to copy a file to a different location with a part of the file name as the filename" Watch "how to copy a file to a different location with a part of the file name as the filename" New topic
Author

how to copy a file to a different location with a part of the file name as the filename

rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
I have set of files residing in my hone directory in different naming conventions as shown below,

ap_aearo_prod.20091104044210.Z.20091106.212217
ap_boise_prod.20091029064716_sorted.Z.20091106.212201
ap_boise_prod.20091029064716.Z.20091106.212158
arms_820i_prod.000003ywS.Z.20091109.064508

I wanted to copy these files to a different location with the filename being only till the "Z" i.e.; this file ap_aearo_prod.20091104044210.Z.20091106.212217 has to be copied as ap_aearo_prod.20091104044210.Z, have to truncate the part after the Z.

I have set of files under this directory. This set of files can be identified by the combination of ap_*_prod*20091106* as I need only these files from this datestamp, I have unwanted files with the same datestamp as well.

Can anyone advise
Himanshu Rawat
Ranch Hand

Joined: Nov 27, 2005
Posts: 141
I tried below code on your mentioned files. Give it a try.




PS : Script was in same directory where files are. Customise it


rawat
SCJP 1.4
rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
Sorry I forgot to mention that I need the script in UNIX. I am sorry for that
Himanshu Rawat
Ranch Hand

Joined: Nov 27, 2005
Posts: 141
It's perl script and ran it on linux/unix
rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
when you say in your code as <*>, I beleive it will pick all the files under that directory but I want only the files matching as I have explained above
Himanshu Rawat
Ranch Hand

Joined: Nov 27, 2005
Posts: 141


this to



This will take only those files starting with ap_

Hope this helps now

Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

create a local script

chmod a+x adhoc.sh, and


http://home.arcor.de/hirnstrom/bewerbung
rahulJ james
Ranch Hand

Joined: Oct 03, 2008
Posts: 123
It worked. Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to copy a file to a different location with a part of the file name as the filename