batch-rename

Command Line (or batch file) rename all files in a folder (Windows)

可紊 提交于 2019-12-10 00:31:04
问题 I need to rename all of the files in a folder with the following filename format; itemID-straight-bottle.png TO itemID-bottle.png How can i accomplish this with a cmd script or in the command line? example; REDHI20806-straight-bottle.png TO REDHI20806-bottle.png I should have said, this is in Windows and i want to use either command line or a batch file to run this renaming on all files in a folder on a specific drive 回答1: short answer On Windows , you can use PowerShell, that is installed by

Linux rename files based on another file in the directory?

让人想犯罪 __ 提交于 2019-12-09 09:46:27
问题 I've got about 750 directories that contain two files each: long_somewhat_random_filename.jpg thumb.jpg What I'd like to do is use find or something similar to rename thumb.jpg to long_somewhat_random_filename_thumb.jpg . My brain's kinda fuzzy at the moment. I could do it with a perl script, but if there's a somewhat easy way to do it in bash, that's easier. 回答1: Give the script below a shot. Right now the echo makes it benign so you can try before you buy so to speak. If you like what you

batch file to find files with double file extensions and remove the last one

折月煮酒 提交于 2019-12-08 12:18:20
问题 I have several folders that have files with double file extensions along with regular file extensions. I need to create a batch script to search all the folders and remove the last extension with any files that have double extensions. None of the file extensions are consistent. Here's an example C:\test\regular.exe C:\test\picture.jpg.doc C:\newtest\document.doc.pdf End Result I need C:\test\regular.exe C:\test\picture.jpg C:\newtest\document.doc 回答1: @ECHO OFF SETLOCAL SET sourcedir=c:

For Loop in Batch File Renames One File Twice

荒凉一梦 提交于 2019-12-08 10:08:21
问题 I wrote this batch file to append some text to the filenames of a set of jpeg files, giving the option to append them before or after the current filename. But for some odd reason when appending before the filename, one file is being proccessed twice getting the result as new_new_FileName.jpg while all other files are getting just new_FileName.jpg. Interesting enough, this problem isn't happening always, as well as when appending after the filename it is always working fine. Following is the

mv: invalid option — '0'

怎甘沉沦 提交于 2019-12-07 11:56:48
问题 How can I rename files with "-" in front of the filename, for example: "-0001.jpg" Everyime I try to run: for i in *; do mv "$i" "${i//-/}"; done or: for i in *; do mv "$i" "${i#*-}"; done I got this error: mv: invalid option -- '0' Try `mv --help' for more information. Thanks for any light! 回答1: mv ./-00008.jpg to/some/where.jpg ^ - start with path... 回答2: as with most gnu commands, use the -- switch before the filename with the hyphen. it signifies "end of switches". 回答3: Put a double -

Rename Files using wildcard paths

限于喜欢 提交于 2019-12-07 10:44:54
问题 Recently I started working and my first task is to write a batch file that automatically changes filenames to filename_date with the original file-ending. For that you should be able to write paths into a textfile (e.g. paths.txt) and when you start the program, it should take any line (=path->file) from there and rename it. I got it to work on my PC quiet well but as I gave it to testing they asked to make the use of wildcards Z:\Path\*.* possible. My current code looks as follows: @echo off

Perl's rename - how to append a counter?

别说谁变了你拦得住时间么 提交于 2019-12-06 15:50:31
There's a nice renaming utility , which comes with Perl's installation. How one would append a counter in the Perl regexp? This is a relevant question e.g. for a problem of numbering files in the current directory: rename 's/^/<here I'd like to have a number of a file being processed>/g' * For example how would one rename: fileA fileB fileC to 1 - fileA 2 - fileB 3 - fileC Edit : I've added the counter feature ( $c variable) - see here . It works fine - but when I try to specify the counter format: rename_c.pl -c 5.2f 's/^/$c - /' * it says: Useless use of concatenation (.) or string in void

PowerShell Command To Bulk Rename Files Sequentially

被刻印的时光 ゝ 提交于 2019-12-06 11:34:31
I am trying to make batch file naming easier for my end users. In photographing our locations, we can sometimes have only 1 photo or 500 depending on the size of the location. The code below works beautifully to bulk rename our photos based on how many files are in the directory: $prefix = "[SomePrefix]" $files = Get-ChildItem $id = 1 $files | foreach { Rename-Item -Path $_.fullname -NewName ( $prefix + ((($id++).tostring()).padleft(($files.count.tostring()).length) -replace ' ','0' ) + $_.extension) } The code pads the photo file name with leading zeroes based on the number of files in the

mv: invalid option — '0'

China☆狼群 提交于 2019-12-05 14:25:37
How can I rename files with "-" in front of the filename, for example: "-0001.jpg" Everyime I try to run: for i in *; do mv "$i" "${i//-/}"; done or: for i in *; do mv "$i" "${i#*-}"; done I got this error: mv: invalid option -- '0' Try `mv --help' for more information. Thanks for any light! mv ./-00008.jpg to/some/where.jpg ^ - start with path... as with most gnu commands, use the -- switch before the filename with the hyphen. it signifies "end of switches". Put a double - before the arguments that can contain "-" in the begin; then there can't be options after --. mv OPTIONS -- ... 来源: https

Rename Files using wildcard paths

放肆的年华 提交于 2019-12-05 11:55:46
Recently I started working and my first task is to write a batch file that automatically changes filenames to filename_date with the original file-ending. For that you should be able to write paths into a textfile (e.g. paths.txt) and when you start the program, it should take any line (=path->file) from there and rename it. I got it to work on my PC quiet well but as I gave it to testing they asked to make the use of wildcards Z:\Path\*.* possible. My current code looks as follows: @echo off setlocal EnableDelayedExpansion cd %~dp0 For /F "tokens=*" %%m in (paths.txt) do ( set path=%%~dpm set