NoWarningCopy Batch File Copier

Miscellaneous tools
Post Reply
Message
Author
User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

NoWarningCopy Batch File Copier

#1 Post by rcrsn51 »

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.

-----------------------------
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.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#2 Post by SFR »

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...
rcrsn51 wrote:Source file paths containing spaces are NOT allowed.
Yeah, that's a pita with <entry> - it stores everything as a single, long, space-separated string.
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"
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.
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.
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.

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]

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#3 Post by rcrsn51 »

Thanks. That's a neat trick to use the IFS. I could use that idea in some other places.

I have updated to v1.1.

[Edit] 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?

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#4 Post by SFR »

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?
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.

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]

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#5 Post by rcrsn51 »

I have uploaded a new v1.1 with $F quoted. It just looked wrong the other way!

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#6 Post by SFR »

One more thing about "$F"/* syntax - it's unable to copy hidden files from source dir.

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]

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#7 Post by rcrsn51 »

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.

User avatar
SFR
Posts: 1800
Joined: Wed 26 Oct 2011, 21:52

#8 Post by SFR »

rcrsn51 wrote:Maybe folders should use something better than "cp -r $F/*". Like tarring the source and extracting it into the destination?
Interesting idea, might work...
___________

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]

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#9 Post by rcrsn51 »

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.

gcmartin

#10 Post by gcmartin »

I know you have put this together using the CP command.

But, does RSYNC command offer such that it handles both the root folder-name contents and its subfolders contents as well with better performance and granularity? Your screen would remain the same.

If it helps, run with it.

User avatar
Flash
Official Dog Handler
Posts: 13071
Joined: Wed 04 May 2005, 16:04
Location: Arizona USA

#11 Post by Flash »

Damn, I was trying to remember rsync but couldn't think of it. You beat me to it. :)

Yes, I think rsync might do what's wanted here. It's a very powerful Puppy command.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#12 Post by MochiMoppel »

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"
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:

Code: Select all

IFS='\n'
SOURCE=${SOURCE// \//$IFS/}
cp -r $SOURCE $DEST
I don't use cp though, only rsync. As much as I hate the file by file warning, no warning at all is no option for me. Rsync allows a dry-run and can list all files that would be overwritten. This is one warning, containing all relevant files, before anything is copied.

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#13 Post by rcrsn51 »

MochiMoppel wrote:I don't use cp though, only rsync.
Code, please. Something I could put in NWC and get the same results.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#14 Post by MochiMoppel »

rsync -a $SOURCE $DEST or, to prevent overwriting of newer files, rsync -au $SOURCE $DEST

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#15 Post by rcrsn51 »

But that's not what the program is designed to do. If 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.

Hence the loop.

User avatar
MochiMoppel
Posts: 2084
Joined: Wed 26 Jan 2011, 09:06
Location: Japan

#16 Post by MochiMoppel »

rcrsn51 wrote:But that's not what the program is designed to do..
But this is what the label says: "This tool does batch copying of files or folders"
If 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.
Of course I want to copy folder A. Anything else would end up in a mess
SFR 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.
You said "Thanks" - now I'm pretty confused what the program should copy and what not

User avatar
rcrsn51
Posts: 13096
Joined: Tue 05 Sep 2006, 13:50
Location: Stratford, Ontario

#17 Post by rcrsn51 »

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.

Post Reply