Looking for an automated way to move files


RockDawg

Recommended Posts

I am looking for an automated way to move the contents of a subdirectory to the parent directory and then delete the resulting empty subfolder.  For example:

 

My movie files are currently stored: Twister\VIDEO_TS\files.  I would like to change them all to Twister\files

 

I dread the thought of manually cutting and pasting for each movie (I have ~570).  Just wondering if there is some quick and easy script or something that would accomplish this unattended.

Link to comment

RockDawg,

 

I'm no Linux expert, but here's an idea (I haven't tried it, so highly suggest you experiment with a dummy file & directories):

 

1.  Telnet into your unRAID server.

2.  Use the "&" command to a command in the background (i.e., the system should immediately return control to you, allowing you to do other things) in combo with...

3.  Use the "mv" command to move your files within the unRAID server (see below)

 

&mv /mnt/disk1/Twister/VIDEO_TS/files /mnt/disk2/Twister/files (you may need to create the Twister\files directory first).

 

 

Link to comment

I would use a batch file or script, something like this pseudocode:

 

for  %dir  in  ( * )

    if  exist  %dir\VIDEO_TS\*.*

        echo  %dir

        move  %dir\VIDEO_TS\*.*  %dir

        del  %dir\VIDEO_TS

 

It will take a lot longer to work out the syntactical details, and test it, than it will take to run this script/batch, perhaps less then 10 minutes to run. I would test it on a temp folder containing copies of 3 movie folders.

 

Since you are only moving directory entries, not moving or copying files, I think it would be better to do everything on a Windows machine, because you will have more choices available in scripting or batching tools.  I'm afraid my batch file skills are too rusty to help.

 

Link to comment

I was hoping that one of the expert scripters here would provide a script or batch file for you, or that you had a favorite batch or scripting tool.  I've created many batch files, some quite complex, but that was in my DOS days, prior to Long File Names.  Batch files have changed some since then, and I'm very rusty.  If I get to it, I'll try to come up with something, doesn't look very hard.  I'm lazily still hoping someone else will though!

 

Link to comment
  • 4 weeks later...

Sorry, don't mean to hijack a thread here, but how about moving files from your inbound box (the computer that you use to get your source files) to your Unraid server?

 

I use Azereus and I can move files from one directory to another after the download is complete, but I'm trying to think of a way to have them moved over to the server after the upload ratio has returned to 1.

 

Any ideas?  Or should I wait for the version of unraid that includes file management under the covers?

 

Thanks.

 

Link to comment
  • 13 years later...

I'd really appreciate if a script was made to do exactly this and if you didn't know the name of the subfolder, in OP's example "VIDEO_TS" is not known say, because you will not know what you will download in the future.

 

Edit: I have found a script that works:

 

#!/bin/bash
find /mnt/user/hms/Materials/Books/Mainfiles -type f -exec mv --backup=numbered -t /mnt/user/hms/Materials/Books/Mainfiles {} +

 

Edited by Arby
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.