file-rename

powershell Rename-Item fail to rename

[亡魂溺海] 提交于 2019-12-21 13:01:03
问题 My powershell script: $dst = 'C:\Temp' #Get all folders in $dst $folders = Get-ChildItem $dst | ?{ $_.PSIsContainer } foreach($folder in $folders) { $cnt = (Get-ChildItem -filter *.txt $folder | Measure-Object).Count $base = ($folder.FullName -split " \[.*\]$")[0] $newname = $("{0} [{1}]" -f $base,$cnt) Write-Host $folder.FullName "->" $newname Rename-Item $folder.FullName $newname } The problem On my first run I get this: PS C:\Temp> C:\Temp\RenameFolders.ps1 C:\Temp\m1 -> C:\Temp\m1 [1] On

Rename and move file with Python

佐手、 提交于 2019-12-21 04:04:45
问题 I have python script that compares existing file names in a folder to a reference table and then determines if it needs to be renamed or not. As it loops through each filename: 'oldname' = the current file name 'newname' = what it needs to be renamed to I want rename the file and move it to a new folder "..\renamedfiles" Can I do the rename and the move at the same time as it iterates through the loop? Update: Apologies, I'm fairly green with scrpting in general but this appears to be pretty

generate random string in php for file name [duplicate]

孤街浪徒 提交于 2019-12-20 10:48:13
问题 This question already has answers here : PHP: How to generate a random, unique, alphanumeric string? (27 answers) Closed 6 years ago . How would I go about creating a random string of text for use with file names? I am uploading photos and renaming them upon completion. All photos are going to be stored in one directory so their filenames need to be unique. Is there a standard way of doing this? Is there a way to check if the filename already exists before trying to overwrite? This is for a

Windows REN command with wildcards doesn't work

我们两清 提交于 2019-12-20 03:26:08
问题 Ok, I know the typical format for the REN command REN source dest and there are several examples to rename using wildcards. Example: REN *.txt *.doc This will rename all your .txt files to .doc. Well, this is all fine and dandy, but I have a bunch of files with extensions .aaaa.bbbb and when I use the command: REN *.aaaa.bbbb *.aaaa I get all of my files with the extenstion .aaaa.aaaa. Now I cannot come up with a REN command to just get .aaaa extension. 回答1: ren *.aaaa.bbbb *. For an

Automate renaming of video files

一个人想着一个人 提交于 2019-12-19 11:19:12
问题 I have a lot of files I want to rename and it would take me a long time to do them manually. They are video files and are usually in this format - "NAME OF SHOW - EPISODE NUMBER - EPISODE NAME", so for example "Breaking Bad - 101 - Pilot". What I would like to do is change the "101" part to my own convention of "S01E01". I figure that in one series of a show the only sequential part of that string is the last number, ie. S01E01, S01E02, S01E03, S01E04 etc... Would anyone be able to give me

Bash: remove numbers at the end of names.

℡╲_俬逩灬. 提交于 2019-12-19 04:55:18
问题 I have files like: alien-skull-2224154.jpg snow-birds-red-arrows-thunderbirds-blue-angels-43264.jpg dead-space-album-1053.jpg How can I remove in bash the "ID" string before .jpg The id is always separated by the before word with "-" Thanks. 回答1: Here's one way using bash parameter substitution: for i in *.jpg; do mv "$i" "${i%-*}.jpg"; done Or for the more general case (i.e. if you have other file extensions), try: for i in *.*; do mv "$i" "${i%-*}.${i##*.}"; done Results: alien-skull.jpg

Renaming a File() object in JavaScript

本秂侑毒 提交于 2019-12-18 18:53:58
问题 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? 回答1: You can add an input tag with the name on it and hide the name property from the user. On the server,

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

僤鯓⒐⒋嵵緔 提交于 2019-12-18 09:27:04
问题 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

How to Batch Rename Files in a macOS Terminal?

你。 提交于 2019-12-17 08:01:32
问题 I have a folder with a series of files named: prefix_1234_567.png prefix_abcd_efg.png I'd like to batch remove one underscore and the middle content so the output would be: prefix_567.png prefix_efg.png Relevant but not completely explanatory: How can I batch rename files using the Terminal? Regex to batch rename files in OS X Terminal 回答1: In your specific case you can use the following bash command ( bash is the default shell on macOS): for f in *.png; do echo mv "$f" "${f/_*_/_}"; done

How to Batch Rename Files in a macOS Terminal?

て烟熏妆下的殇ゞ 提交于 2019-12-17 08:01:27
问题 I have a folder with a series of files named: prefix_1234_567.png prefix_abcd_efg.png I'd like to batch remove one underscore and the middle content so the output would be: prefix_567.png prefix_efg.png Relevant but not completely explanatory: How can I batch rename files using the Terminal? Regex to batch rename files in OS X Terminal 回答1: In your specific case you can use the following bash command ( bash is the default shell on macOS): for f in *.png; do echo mv "$f" "${f/_*_/_}"; done