Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Sat 24 Sep 2016, 20:42
All times are UTC - 4
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
NoWarningCopy Batch File Copier
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 2 [17 Posts]   Goto page: 1, 2 Next
Author Message
rcrsn51


Joined: 05 Sep 2006
Posts: 10984
Location: Stratford, Ontario

PostPosted: Mon 16 May 2016, 08:20    Post subject:  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.

-----------------------------
screenie.png
 Description   
 Filesize   19.25 KB
 Viewed   278 Time(s)

screenie.png

NoWarningCopy-1.1.pet
Description 
pet

 Download 
Filename  NoWarningCopy-1.1.pet 
Filesize  6.05 KB 
Downloaded  46 Time(s) 

Last edited by rcrsn51 on Wed 18 May 2016, 15:44; edited 5 times in total
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1513

PostPosted: Mon 16 May 2016, 11:11    Post subject:  

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:
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!
Screenshot.jpg
 Description   
 Filesize   72.82 KB
 Viewed   317 Time(s)

Screenshot.jpg


_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
rcrsn51


Joined: 05 Sep 2006
Posts: 10984
Location: Stratford, Ontario

PostPosted: Mon 16 May 2016, 11:24    Post subject:  

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?
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1513

PostPosted: Mon 16 May 2016, 13:21    Post subject:  

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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
rcrsn51


Joined: 05 Sep 2006
Posts: 10984
Location: Stratford, Ontario

PostPosted: Mon 16 May 2016, 13:34    Post subject:  

I have uploaded a new v1.1 with $F quoted. It just looked wrong the other way!
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1513

PostPosted: Mon 16 May 2016, 13:55    Post subject:  

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

Greetings!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
rcrsn51


Joined: 05 Sep 2006
Posts: 10984
Location: Stratford, Ontario

PostPosted: Mon 16 May 2016, 14:15    Post subject:  

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.
Back to top
View user's profile Send private message 
SFR


Joined: 26 Oct 2011
Posts: 1513

PostPosted: Mon 16 May 2016, 14:53    Post subject:  

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!

_________________
[O]bdurate [R]ules [D]estroy [E]nthusiastic [R]ebels => [C]reative [H]umans [A]lways [O]pen [S]ource
Omnia mea mecum porto.
Back to top
View user's profile Send private message 
rcrsn51


Joined: 05 Sep 2006
Posts: 10984
Location: Stratford, Ontario

PostPosted: Mon 16 May 2016, 15:14    Post subject:  

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.
Back to top
View user's profile Send private message 
gcmartin


Joined: 14 Oct 2005
Posts: 6714
Location: Earth

PostPosted: Mon 16 May 2016, 16:57    Post subject:  

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.

_________________
Get ACTIVE Create Circles; Do those good things which benefit people's needs!
We are all related ... Its time to show that we know this!
3 Different Puppy Search Engines or use DogPile
Back to top
View user's profile Send private message 
Flash
Official Dog Handler


Joined: 04 May 2005
Posts: 12112
Location: Arizona USA

PostPosted: Mon 16 May 2016, 21:25    Post subject:  

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

Yes, I think rsync might do what's wanted here. It's a very powerful Puppy command.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1110
Location: Japan

PostPosted: Mon 16 May 2016, 21:47    Post subject:  

SFR wrote:
Code:
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:
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.
Back to top
View user's profile Send private message 
rcrsn51


Joined: 05 Sep 2006
Posts: 10984
Location: Stratford, Ontario

PostPosted: Tue 17 May 2016, 01:03    Post subject:  

MochiMoppel wrote:
I don't use cp though, only rsync.

Code, please. Something I could put in NWC and get the same results.
Back to top
View user's profile Send private message 
MochiMoppel


Joined: 26 Jan 2011
Posts: 1110
Location: Japan

PostPosted: Tue 17 May 2016, 01:26    Post subject:  

rsync -a $SOURCE $DEST or, to prevent overwriting of newer files, rsync -au $SOURCE $DEST
Back to top
View user's profile Send private message 
rcrsn51


Joined: 05 Sep 2006
Posts: 10984
Location: Stratford, Ontario

PostPosted: Tue 17 May 2016, 01:30    Post subject:  

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.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 2 [17 Posts]   Goto page: 1, 2 Next
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Advanced Topics » Additional Software (PETs, n' stuff) » Utilities
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0731s ][ Queries: 12 (0.0076s) ][ GZIP on ]