Xfce Forum

Sub domains
 

You are not logged in.

#1 2015-03-14 22:17:41

birch
Member
Registered: 2014-07-12
Posts: 63

Thunar Custom Action - Move Selected Files into Date Stamped Folder

I have a command that moves selected files into a folder named "dir":

mkdir %d/dir && cd %d; for file in %N; do mv "$file" "dir/${file%%.*}"; done

How can I modify this command so that it will create a folder with the date and move the selected files into that folder?

I've tried this command:

mkdir %d/"$(date)" && cd %d; for file in %N; do mv "$file" ""$(date)"/${file%%.*}"; done

It creates the folder with the date as name, but it doesn't move the files into the folder. I figure I need to put something in place of the second "$(date)".

Last edited by birch (2015-03-14 22:18:43)

Offline

#2 2015-03-14 22:39:44

sonycdr
Member
Registered: 2009-01-30
Posts: 130

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

look if you can adapt this one http://forum.xfce.org/viewtopic.php?id=9384

Edit:
fix the double quote "" in: do mv "$file" ""$(date)"/${file%%.*}";
and you have to specify the date format -> man date

here how can be done:

NOW=$(date +'%Y-%m-%d'); echo $NOW; for file in *; do echo "$file" "$NOW/${file%%.*}"; done

example output:

2015-03-14
file1 2015-03-14/file1
file2 2015-03-14/file2
file3 2015-03-14/file3

Last edited by sonycdr (2015-03-14 23:03:01)

Offline

#3 2015-03-14 22:46:55

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

write a script and execute it with a custom action, thunars command entry is not a shell

PS but I'm actually more suprised that the ";" works in thunar since the terminal fails on it

Last edited by sixsixfive (2015-03-14 23:07:20)

Offline

#4 2015-03-14 23:52:41

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

sonycdr wrote:

look if you can adapt this one http://forum.xfce.org/viewtopic.php?id=9384

Tx! I prefer the solution at the link. Then I can enter any custom name, which I like more than the automatic date stamp.

Offline

#5 2015-03-14 23:54:14

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

sixsixfive wrote:

write a script and execute it with a custom action, thunars command entry is not a shell

PS but I'm actually more suprised that the ";" works in thunar since the terminal fails on it

What do you mean? I use a lot of commands in Custom Actions that have the semicolon.

Offline

#6 2015-03-14 23:59:16

sonycdr
Member
Registered: 2009-01-30
Posts: 130

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

yes it works, just be sure you have a space between semicolon and command.

@birch: test this one and try to adapt for your need:

(NOW=$(date +"%%Y-%%m-%%d"); echo mkdir -p %d/$NOW; for file in %N; do echo mv -n "$file" -t "$NOW"; done)> test.txt

if it suit for you, just remove all "echo" and this wrapper "()> test.txt"

Offline

#7 2015-03-15 00:23:32

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

sonycdr wrote:

yes it works, just be sure you have a space between semicolon and command.

@birch: test this one and try to adapt for your need:

(NOW=$(date +"%%Y-%%m-%%d"); echo mkdir -p %d/$NOW; for file in %N; do echo mv -n "$file" -t "$NOW"; done)> test.txt

if it suit for you, just remove all "echo" and this wrapper "()> test.txt"

Great! That works. I can use this in addition to the Zenity command in your link. Another question: How to add the time with seconds to the command? Like so: 20:23:05

Last edited by birch (2015-03-15 00:24:09)

Offline

#8 2015-03-15 00:31:14

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

I tried this: date "+%Y-%m-%dT%H:%M:%S%:z"

But gives the folder a name like "2015-03-14-1426379126".

I'd prefer "2015-03-14-20:23:05".

Offline

#9 2015-03-15 01:07:40

sixsixfive
Member
From: behind you
Registered: 2012-04-08
Posts: 579
Website

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

birch wrote:

What do you mean? I use a lot of commands in Custom Actions that have the semicolon.

I said terminal eg try:

xfce4-terminal -e "echo 5;sleep 5;echo 4;read"

do the same with xterm or terminology

Offline

#10 2015-03-15 01:26:41

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

I figured out the time stamp:

NOW=$(date +"%%Y-%%m-%%d-%%H:%%M:%%S"); mkdir -p %d/$NOW; for file in %N; do mv -n "$file" -t "$NOW"; done

Last edited by birch (2015-03-15 01:26:53)

Offline

#11 2015-03-15 01:27:55

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

sixsixfive wrote:
birch wrote:

What do you mean? I use a lot of commands in Custom Actions that have the semicolon.

I said terminal eg try:

xfce4-terminal -e "echo 5;sleep 5;echo 4;read"

do the same with xterm or terminology

I run the command and a terminal opens for a split second and closes.

Offline

#12 2015-03-15 01:45:21

sonycdr
Member
Registered: 2009-01-30
Posts: 130

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

@Birch
I recommand you a format without colon or semicolon because is not portable on other file-system
like that: 20150315-023713

Offline

#13 2015-03-15 19:56:14

birch
Member
Registered: 2014-07-12
Posts: 63

Re: Thunar Custom Action - Move Selected Files into Date Stamped Folder

Good to know, tx! I guess I should do what sixsixfive suggested and test my scripts in zsh or dash.

Offline

Board footer

Powered by FluxBB