My task is to copy all files from many directories in one. The big problem i encounter is that some files in different directory have the same names. Is they are way to copy the files that have same names in a sub directory ( need to preserve the name of the files unchanged )
I have list with all the files i have to copy.
Example
Its not possible to have two files with the same name in one directory. One suggestion is, you can append a number to it.
For e.g., you could copy "Desktop.jpg" from different locations as "Desktop01.jpg", "Desktop02.jpg"... and so on...
How can your destination directory hold "two files" with the same name?
Option (1) You have prefix/append extra characters for each duplicate file before copying
(2) Even in Destination directory maintain the directory structure.
For example. it seems you have at least four copies of DeskTop.jpg so you would need at least three subdirectories to preserve all the files. What are you going to name those subdirectories so you can tell which files are where?
As other poster suggested, you could also append something to prevent duplicate file names. But sounds confusing.
Why do you want to copy all the files together into one directory in the first place? What's the advantage?
If there is a good reason to do this, I'm sure it could be done: Get name of file to copy. Test if file already in destination directory. If no, copy it. If yes, create new subdirectory and copy file to subdirectory instead.
Is they are way to make script that copy the files that have same names in a sub directory :o ?
---------- Post updated at 02:35 AM ---------- Previous update was at 02:28 AM ----------
The advantage is easy access.
What you suggest looks exactly what i am after, but need assist with it: Get name of file to copy. Test if file already in destination directory. If no, copy it. If yes, create new subdirectory and copy file to subdirectory instead
I don't mind copy all the files from the list in a new destination preserving the folder tree as well, but again i need help because don`t know how to preserve the directory tree.
It would help if you could compose a test case. Give a sample of eight or so file names with complete paths, and the final complete paths you want.
Of course it's possible to do most anything. But sometimes the cure is worse than the disease. Why do you want all the files in one directory? The whole point of having directories is to organize information. What would be the result if you took all the papers out of your file cabinet and emptied them onto your desk? :o Is there any chance you could use tar or zip to accomplish whatever you are trying to do?
Well actually the files i need to copy are files i was specifically looking for, and they have something in common, so getting them in the same directory wood not presan an issue.
all this lines are in a file datafinal. Path to this file is:
/home/gogo/Desktop/datafinal
The files i will copy will be always from removable device, hard drive or flash, dunno if this is relevant.
Need the files here:
/home/gogo/Documents/filetumb
Do it anyway you can, all files in one directory with the files who have duplicated names put in a sub directory OR copy all files with they are path in the folder i pointed.