NoWarningCopy Batch File Copier
NoWarningCopy Batch File Copier
Update: Version 1.1 now allows filenames and paths that contain spaces using SFR's technique below.
This is largely a proof-of-concept app that addresses the following issue. Suppose you have a batch of files in folder A. You want to copy them to Folder B which contains files with the same names. All file managers will recognize the situation and give you the message "Do you want to over-write this file?". Because you are copying multiple files, there should also be a "Yes to all" option. Unfortunately, this doesn't work properly in ROX, making you answer "Yes" to each file before it is copied.
In some versions of ROX, this problem has been "solved" by removing the "Do you want to over-write this file?" message for ALL file copying. This can lead to dangerous unintended consequences.
The NoWarningCopy tool simply performs the batch copy with no prompting. The source can be the name of Folder A or a group of files selected in ROX and dragged into the box. The destination is Folder B.
If the source folder A contains subfolders of files, NoWarningCopy may not behave the way you want. This feature is not fully tested.
The PET installs into the Utility menu.
-----------------------------
This is largely a proof-of-concept app that addresses the following issue. Suppose you have a batch of files in folder A. You want to copy them to Folder B which contains files with the same names. All file managers will recognize the situation and give you the message "Do you want to over-write this file?". Because you are copying multiple files, there should also be a "Yes to all" option. Unfortunately, this doesn't work properly in ROX, making you answer "Yes" to each file before it is copied.
In some versions of ROX, this problem has been "solved" by removing the "Do you want to over-write this file?" message for ALL file copying. This can lead to dangerous unintended consequences.
The NoWarningCopy tool simply performs the batch copy with no prompting. The source can be the name of Folder A or a group of files selected in ROX and dragged into the box. The destination is Folder B.
If the source folder A contains subfolders of files, NoWarningCopy may not behave the way you want. This feature is not fully tested.
The PET installs into the Utility menu.
-----------------------------
- Attachments
-
- screenie.png
- (19.25 KiB) Downloaded 315 times
-
- NoWarningCopy-1.1.pet
- (6.05 KiB) Downloaded 137 times
Last edited by rcrsn51 on Wed 18 May 2016, 19:44, edited 5 times in total.
Hey Rcrsn51
Nice tool.
I also prefer ROX working the old way - even if it's not so convenient, at least it's less prone to accidental overwrites.
Thankfully in Fatdog we have the old behavior preserved...
But I just realized it actually can be easily work-arounded.
When you dnd items onto <entry>, they are always stored with full paths, so each item always starts with /, therefore all we need to do is to replace all ' /' strings with '<separator>/', where <separator> character should be something not likely to be found in filenames, e.g. 0xff:
Works for me with crazy filenames (see scrsht).
The only scenario I can think of where it could fail is copying a file from a directory, whose name ends with a space (e.g. /root/a /somefile), but that's rather highly unlikely.
Greetings!
Nice tool.
I also prefer ROX working the old way - even if it's not so convenient, at least it's less prone to accidental overwrites.
Thankfully in Fatdog we have the old behavior preserved...
Yeah, that's a pita with <entry> - it stores everything as a single, long, space-separated string.rcrsn51 wrote:Source file paths containing spaces are NOT allowed.
But I just realized it actually can be easily work-arounded.
When you dnd items onto <entry>, they are always stored with full paths, so each item always starts with /, therefore all we need to do is to replace all ' /' strings with '<separator>/', where <separator> character should be something not likely to be found in filenames, e.g. 0xff:
Code: Select all
SEPARATOR="`echo -e '\xff'`"
oldIFS="$IFS"; IFS="$SEPARATOR"
for F in ${SOURCE// \//${SEPARATOR}/}; do
if [ -f $F ]; then
cp $F "$DEST"
elif [ -d $F ]; then
cp -r $F/* "$DEST"
fi
done
IFS="$oldIFS"
The only scenario I can think of where it could fail is copying a file from a directory, whose name ends with a space (e.g. /root/a /somefile), but that's rather highly unlikely.
Yep, I changed it to just cp -r $F "$DEST", so it copies the chosen dirs themselves (with everything inside of them), not their contents alone.rcrsn51 wrote:If the source folder A contains subfolders of files, NoWarningCopy may not behave the way you want. This feature is not fully tested.
Greetings!
- Attachments
-
- Screenshot.jpg
- (72.82 KiB) Downloaded 350 times
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
Most likely. I think I simply forgot to do it before I conducted the test, but everything went well, so I left it as-is.rcrsn51 wrote:I was surprised that you don't need to quote $F in the new code, even though it now contains spaces. Does the IFS also apply to it?
Thanks for the update &
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
I've always wondered why bash won't pattern-match for hidden files without a bunch of tricks. I guess that it really-really wants to keep them hidden.
Maybe folders should use something better than "cp -r $F/*". Like tarring the source and extracting it into the destination? This is more than I'm interested in pursuing.
Maybe folders should use something better than "cp -r $F/*". Like tarring the source and extracting it into the destination? This is more than I'm interested in pursuing.
Interesting idea, might work...rcrsn51 wrote:Maybe folders should use something better than "cp -r $F/*". Like tarring the source and extracting it into the destination?
___________
Yet another thing that just occured to me: symlinks.
Plain cp will not overwrite a destination symlink, but a file it points to.
'--remove-destination' comes to rescue, I guess.
Similarily the other way around - if you want to copy a symlink, a file it points to will be copied instead.
In this case '-P, --no-dereference' would do.
Also: permissions/ownership.
From what I've seen different FMs behave a bit differently in this regard, but if you want to preserve them I suggest '--preserve=all' option.
Greetings!
[color=red][size=75][O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource[/size][/color]
[b][color=green]Omnia mea mecum porto.[/color][/b]
[b][color=green]Omnia mea mecum porto.[/color][/b]
I am going to assume that NWC would be used in the following kind of situation.
1. You copy a bunch of files, like JPEGs out of Folder B to a temporary Folder A.
2. You somehow modify the files, like resizing them.
3. You then want to copy the files back to Folder B with their original names. (Personally, I would never do this.)
In that case, you wouldn't need to worry about hidden files or permissions - you just need a plain vanilla copy. NWC would be good enough.
1. You copy a bunch of files, like JPEGs out of Folder B to a temporary Folder A.
2. You somehow modify the files, like resizing them.
3. You then want to copy the files back to Folder B with their original names. (Personally, I would never do this.)
In that case, you wouldn't need to worry about hidden files or permissions - you just need a plain vanilla copy. NWC would be good enough.
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
Why the loop and the file type check? Are you worried about command line length? This is - basically! - what I use for years now, copying hundreds of files in one batch:SFR wrote:Code: Select all
SEPARATOR="`echo -e '\xff'`" oldIFS="$IFS"; IFS="$SEPARATOR" for F in ${SOURCE// \//${SEPARATOR}/}; do if [ -f $F ]; then cp $F "$DEST" elif [ -d $F ]; then cp -r $F/* "$DEST" fi done IFS="$oldIFS"
Code: Select all
IFS='\n'
SOURCE=${SOURCE// \//$IFS/}
cp -r $SOURCE $DEST
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
- MochiMoppel
- Posts: 2084
- Joined: Wed 26 Jan 2011, 09:06
- Location: Japan
But this is what the label says: "This tool does batch copying of files or folders"rcrsn51 wrote:But that's not what the program is designed to do..
Of course I want to copy folder A. Anything else would end up in a messIf you put the name of Folder A in the box, you want to copy the CONTENTS of Folder A to Folder B, not Folder A itself.
You said "Thanks" - now I'm pretty confused what the program should copy and what notSFR wrote:Yep, I changed it to just cp -r $F "$DEST", so it copies the chosen dirs themselves (with everything inside of them), not their contents alone.
The opening post of this thread describes a specific situation and the problem it poses. How do you copy a bunch of files from Folder A to Folder B - either by specifying the name of Folder A or the names of the individual files - without being warned about overwriting? This was further clarified in my fifth post with a detailed example.
It does NOT ask how to copy the ENTIRE Folder A into Folder B - that is a different situation.
The code in its current form does exactly what is required, except for the extreme cases as listed by SFR.
If someone has more efficient VERIFIED code, I would be happy to see it - provided that it meets the original specifictions.
It does NOT ask how to copy the ENTIRE Folder A into Folder B - that is a different situation.
The code in its current form does exactly what is required, except for the extreme cases as listed by SFR.
If someone has more efficient VERIFIED code, I would be happy to see it - provided that it meets the original specifictions.