How to copy files with the same filenames as those in another folder to that same folder?
Hello All
A similar question like this was asked before but I need to change part of the question.
I've two folders, Folder A contains some image files in 150 subfolders;
Folder B contains text files in 350 subfolders.
All image files in Folder A have the same filename as the text files in Folder B.
That is to say, regardless of file extension, 10000.txt files in subfolders of Folder B share the same filename as 10000.tif files in subfolders of Folder A. For example 00011020.tif in subfolder 0120 of Folder A is able to find its corresponding 00011020.txt file in subfolder 0300 of Folder B. So same filename are not in the corresponding subfolders.
My question is:
How to copy the text files that share the same filename as those image files to the corresponding subfolders in Folder A. I want to combine all files in the subfolders of Folder A.
Thanks in advance for your help.
And, if you have a filename like a.b.txt, this will give you a while I expect that you really want a.b. So, BASE=$(basename $TXTFILE .txt) would be better. But the loop could be made more efficient using:
But, even if there is only one file in each of the 350 subdirectories in folderB, this will still be running find 351 times (which will make this a very slow script). And, if there is a missing .txt file, you won't know about it; and if there is a missing .tif file you'll have a malformed cp command.
The following script runs find twice, and awk once no matter how many files need to be copied and prints diagnostics for missing .txt and .tif files:
I suggest that you remove the | /bin/ksh from the last line of the script until you see that it will do what you want. (Note that the awk script is printing shell commands to be run by the shell; not running the commands themselves.)
You may need to change the pathname to the Korn shell (in both the 1st and last line of the script) if you move to a different system. And, if you're using a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk, /usr/xpg6/bin/awk, or nawk.
Everybody, thanks for the responses. I'm an idiot. I was so happy to find someone with my issue that I didn't bother looking at the OS. I needed this for Windows. I've found a solution for Windows.
Thanks for your help and sorry for wasting your time.
hello
does someone want to help me for this one ?
i want to rename files & a folder according to the similarities in filenames
for example :
the file with the good name
cglogo tougl1953 dgmel bogd 01 -- ttgductoog ggdté gollogtd.ext1the others files needed to be renamed
cglogo... (5 Replies)
Hi,
I have a folder which contains some files like this.
bin.000001
bin.000002
bin.000003
bin.000004
bin.000005
bin.000129
bin.index
I want to copy all these files to a new folder except the last files.
Please provide some ideas.
Please use next time code tags for your code... (6 Replies)
Hi experts,
I am coming to you with this basic question on copying a folder and its content from one location to another folder using PERL script.
This is my requirement.
I have a folder AB under /users/myhome
I want to copy AB and its contents to /user/workspace.
Finally it should... (1 Reply)
This has been tearing my hair out.
I need to:
1: compare server1:/data/archive/ to server2:/data/archive/ (through rsync, ssh, etc)
2: filenames that don't match, get copied (scp) to server2:/data/
server1 and server2 have ssh, scp, rsync access between eachother.
Is there any option in... (3 Replies)
Hi ,
I have a file like this, i need to trace its path and copy the files from its path to one folder. I need to replace elib.com,melib.com to F:\.Here i need to copy to a folder called image. Please help
http://elib.com/SHC/NLNLHB/020001498.pdf ... (4 Replies)
Hi everyone,
when I try to copy *.gz files run cp within the correct source folder it works as follow:
Source folder = C:/Documents and Settings/user/Recent papers/2771/
Destination folder = C:/Documents and Settings/user/My documents/1532/temp
cp *.gz "C:/Documents and Settings/user/My... (2 Replies)
Hi, all:
I've got two folders, folder A contains some image files (say, 100 files) in .jpg format;
folder B contains all description files (say, 500 files) in .txt format.
All image files in folder A are able to find their corresponding description files in folder B.
That is to say,... (3 Replies)
Hi all,
*I use Uwin and Cygwin emulator.
I´m trying to search for all text files in the current folder (C/Files) and its sub folders using
find -depth -name "*.txt"
The above command worked for me, but now I would like to copy all found text files to a new folder (C/Files/Text) with ... (4 Replies)
Hello all,
I'm trying to accomplish that if a file gets written to folder /path/to/a/ it gets automatically copied into /path/to/b/ the moment its get written.
I thought of writing a shell script and cron it that every X amount of minutes it copies these files over but this will not help me... (2 Replies)
For example,
/tmp/folder1
includes /tmp/folder1/a /tmp/folder1/b
/tmp/folder2
includes /tmp/c
Is there a command without removing files in /tmp/folder2 first to copy the /tmp/folder1 to /tmp/folder2?
and the result should be
/tmp/folder2 will include only /tmp/folder2/a... (2 Replies)