file-rename

Renaming a File() object in JavaScript

浪尽此生 提交于 2019-12-01 02:40:51
I'd like for my users to be able to re-name a file before uploading it. I have a File object in Javascript which has a name property that is already set, but i'd like for this to be able to be updated. Right now doing the obvious myFile.name = "new-name.txt" returns an error that this property is read only. What's the best way of changing the name property on a JavaScript File object? You can add an input tag with the name on it and hide the name property from the user. On the server, just use the input as the name and ignore the default name. Now that file.name is a read-only property, I've

Prevent a user from deleting, moving or renaming a file

十年热恋 提交于 2019-11-30 18:25:11
What I am trying to do is while my program is using a file, I want to keep the user from renaming, deleting, or moving the file (well... a move is a delete and a create at a different location according to Windows FileSystemWatcher , but I digress). It has been suggested that I use FileStream.Lock or use a Mutex . However, FileStream.Lock seems only to prevent the file from being modified which I am trying to allow . Also, I am very unsure as to if a mutex can lock a file, although I am still reading on it with in the .Net 4.0 library. Does anyone have any advice on utilizing either one and if

Paperclip - rename file before saving

六眼飞鱼酱① 提交于 2019-11-30 11:48:43
问题 I use this method for renaming the image before the saving: def rename_avatar self.avatar.instance_write :file_name, Time.now.to_i.to_s end before_post_process :rename_avatar The image is renamed by the current time, but there's not added the file type, instead of 1334487964.jpg is saved only 1334487964. . What I missing there? I thought :file_name contains only the file name - without the file type 回答1: This is the way how I fix my issue: def rename_avatar #avatar_file_name - important is

Renaming files with Bash, removing prefix and suffix

流过昼夜 提交于 2019-11-30 09:37:44
I want to rename a bunch of files using bash, transforming this file pattern: prefix - name - suffix.txt Into this one: name.txt For that I wrote the following script: find . -name "*.txt" | while read f do mv "${f}" "${f/prefix - /}" done find . -name "*.txt" | while read f do mv "${f}" "${f/ - suffix/}" done It works, but I'd like to perform the renaming using a single loop. Is it possible? Another approach, for fun, using regular expressions: regex='prefix - (.*) - suffix.txt' for f in *.txt; do [[ $f =~ $regex ]] && mv "$f" "${BASH_REMATCH[1]}.txt" done Actually, using the simple pattern '

Paperclip - rename file before saving

时光总嘲笑我的痴心妄想 提交于 2019-11-30 00:27:17
I use this method for renaming the image before the saving: def rename_avatar self.avatar.instance_write :file_name, Time.now.to_i.to_s end before_post_process :rename_avatar The image is renamed by the current time, but there's not added the file type, instead of 1334487964.jpg is saved only 1334487964. . What I missing there? I thought :file_name contains only the file name - without the file type This is the way how I fix my issue: def rename_avatar #avatar_file_name - important is the first word - avatar - depends on your column in DB table extension = File.extname(avatar_file_name)

Rename uploaded file (php)

佐手、 提交于 2019-11-29 18:19:50
I'm trying to rename a file I'm uploading. I will be uploading a xml or pdf file, and I want it to be in a folder called "files/ orderid /" and the filename should also be orderid .extension The file uploads fine, and the folder id created with the correct name, but all the ways I have tried to rename it fails. Below is my code. // include database connection include 'config/database.php'; // get passed parameter value, in this case, the record ID $id=isset($_GET['orderid']) ? $_GET['orderid'] : die('FEJL: Ordren kunne ikke findes.'); // page header $page_title="Upload pdf og/eller xml fil";

python os.rename(…) won't work !

痞子三分冷 提交于 2019-11-29 16:24:43
I am writing a Python function to change the extension of a list of files into another extension, like txt into rar, that's just an idle example. But I'm getting an error. The code is: import os def dTask(): #Get a file name list file_list = os.listdir('C:\Users\B\Desktop\sil\sil2') #Change the extensions for file_name in file_list: entry_pos = 0; #Filter the file name first for '.' for position in range(0, len(file_name)): if file_name[position] == '.': break new_file_name = file_name[0:position] #Filtering done ! #Using the name filtered, add extension to that name new_file_name = new_file

Renaming files with Bash, removing prefix and suffix

与世无争的帅哥 提交于 2019-11-29 14:46:03
问题 I want to rename a bunch of files using bash, transforming this file pattern: prefix - name - suffix.txt Into this one: name.txt For that I wrote the following script: find . -name "*.txt" | while read f do mv "${f}" "${f/prefix - /}" done find . -name "*.txt" | while read f do mv "${f}" "${f/ - suffix/}" done It works, but I'd like to perform the renaming using a single loop. Is it possible? 回答1: Another approach, for fun, using regular expressions: regex='prefix - (.*) - suffix.txt' for f

php - Differences between copy, rename and move_uploaded_file

倾然丶 夕夏残阳落幕 提交于 2019-11-29 13:29:21
Are there differences when I use that functions? Why should I use one instead of the other one... copy() copies the file - you now have 2 files, and for large files, this can take very long rename() changes the file's name, which can mean moving it between directories. move_uploaded_file() is basically the same as rename() , but it will only work on files that have been uploaded via PHP's upload mechanism. This is a security feature that prevents users from tricking your script into showing them security-relevant data. In the future, I suggest looking up such information in the PHP Manual

Batch rename files

匆匆过客 提交于 2019-11-28 18:48:19
I want to batch re-name a number of files in a directory so that the preceding number and hypen are stripped from the file name. Old file name: 2904495-XXX_01_xxxx_20130730235001_00000000.NEW New file name: XXX_01_xxxx_20130730235001_00000000.NEW How can I do this with a linux command? This should make it: rename 's/^[0-9]*-//;' * It gets from the beginning the block [0-9] (that is, numbers) many times, then the hyphen - and deletes it from the file name. If rename is not in your machine, you can use a loop and mv : mv "$f" "${f#[0-9]*-}" Test $ ls 23-aa hello aaa23-aa $ rename 's/^[0-9]*-//;'