Substituting characters in filenames

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Substituting characters in filenames Wed May 24, 2017 10:40 am • by jimhuls
At work I use OneDrive for Business and regularly get files that I need to save in the cloud. Some of these files contain characters that OneDrive for Business does not like thus they don't get synced. My thought was that I could use Hazel to monitor the entire folder for OneDrive for Business to watch for any files that contain these illegal characters. My first thought is to try writing a shell script that reads in the name when captured and renames the file with substituted legal characters within that folder. So there are two questions that stand out...

1. Is there a method to do this without writing a script?
2. If I write a script, I noticed that $1 is used to read the filename but how do I read the path where the file is contained.

I'm not exactly super fluent in writing scripts but I can usually get the job done so option 1 would be nice. If I go with option 2 of writing a script, I'm not familiar with how Hazel interacts with said script to pass that information. Would the path be part of the filename(i.e..../Users/DTrump/OneDrive - WhiteHouse/Twitter Password!.pdf)

The illegal characters that aren't allowed in OneDrive for Business are \ / : * ? " < > !

Thanks for any help one can offer.
jimhuls
 
Posts: 2
Joined: Wed May 24, 2017 10:20 am

Re: Substituting characters in filenames Wed May 24, 2017 11:20 am • by Mr_Noodle
You can use the "Replace text" function. In the rename action, click on the "Name" attribute. You should see it there.

As for scripts, $1 contains the full path. While you probably don't need to write a script anymore, for future reference, I suggest reading up in the manual as it contains more details.
Mr_Noodle
Site Admin
 
Posts: 11872
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Substituting characters in filenames Thu May 25, 2017 1:46 pm • by jimhuls
Mr_Noodle wrote:You can use the "Replace text" function. In the rename action, click on the "Name" attribute. You should see it there.

As for scripts, $1 contains the full path. While you probably don't need to write a script anymore, for future reference, I suggest reading up in the manual as it contains more details.


Thanks...I apologize for bothering you about this. It wasn't long after I posted this that I figured it out and then didn't have time due to some legal and medical emergencies that came up to see if there was a way to cancel it.
jimhuls
 
Posts: 2
Joined: Wed May 24, 2017 10:20 am


Return to Support