osx,bash,directory,batch-rename
The following script will work as desired : dir=$1 find $dir -name "*Screenshot*" -type f | while read file do base=$(basename $file) dirpath=$(dirname $file) extr=$(echo $file | awk -F/ '{print $(NF-2)}') #extracts the grandparent directory mv $file $dirpath/$extr-$base done As @loneswap mentioned, this must be invoked as a script. So...
python,regex,python-2.7,batch-rename
re.sub() returns the altered string, but you ignore the return value. You want to re-assign the result to filename_zero: filename_zero = re.sub("[^\d-]", "", filename_zero) I've corrected your regular expression as well; this removes anything that is not a digit or a dash from the base filename: >>> re.sub(r'[^\d-]', '', '1234567-1(crop...
powershell,powershell-v2.0,reverse,batch-rename
This should get the job done. $Path = "C:\Users\Test" $regex = "^(Spring|Summer|Fall|Winter)\s+\d{4}$" Get-ChildItem $Path | Where-Object {$_.PSIsContainer -and $_.Name -match $regex} | Rename-Item -NewName {$split = $_.Name -split "\s+"; "{0} {1}" -f $split[1],$split[0]} We use that regex to filter out the folder that fit your convention. Should be a little...
for-loop,cmd,batch-rename,variable-expansion
for %a in (*) do ( set tmpx=%a & echo %tmpx% ) The problem with the previous code is delayed expansion. Yes, you enabled it, but you have not used it, and depending on how you enabled it, it will not work In cmd, when a line or block of...
batch-file,batch-processing,batch-rename
In the simplest case: as your text file lines have relative paths then the batch file has to be executed from the relative folder in question. If your text file has fully qualified paths names then it can be launched from anywhere....
Try, in place of for %%j in (*.jpg) do ( for /f "delims=" %%j in ('dir /b /a-d *.jpg') do ( if you ECHO REN... instead of REN, just temporarily, then batch will simply report the required rename, but not execute it. Remove the ECHO to perform the rename What...
windows,batch-file,cmd,batch-rename
Not tested: @echo off setlocal set "source_dir=C:\source" set "destination_dir=C:\dest" set /p "mask=Enter a pattern: " pushd "%source_dir%" for %%# in ("%mask%_*") do ( copy /y "%%~#" "%destination_dir%" ) endlocal ...
windows,batch-file,batch-rename
@echo off for /L %%i in (1,1,9) do ren "%1%%i.mp3" "%10%%i.mp3" Previous Batch file requires the initial name in the first parameter, for example: test.bat disc5 You may also use previous method directly in the command-line: for /L %i in (1,1,9) do ren "disc5%i.mp3" "disc50%i.mp3" ...
linux,shell,rename,command-line-interface,batch-rename
If you don't want to use rename, you mention you have tried various things, then with only built-in bash utils, you can do this. for x in `find . -maxdepth 1 -type f -name "*.JPG"` ; do mv "$x" `echo $x|sed 's/JPG/jpg/g'`; done The backticks around find run the expression...
@ECHO OFF SETLOCAL SET "sourcedir=U:\sourcedir" FOR /f "tokens=1,3delims=)-." %%a IN ( 'dir /b /a-d "%sourcedir%\*) - *.kam" ' ) DO FOR /f "tokens=*" %%u IN ("%%b") DO ECHO REN "%sourcedir%\%%a) -%%b.kam" "%%u - %%a).kam" GOTO :EOF This should solve your problem. You'd need to change yur sourcedir of course. The...
c#,csv,file-rename,batch-rename
In my opinion, a better solution would be to use a plain old foreach and not a call to ToList().ForEach(). var lines = File.ReadAllLines(filepath); var data = from l in lines.Skip(1) let split = l.Split(',') select new OldNew { oldFile = split[0], newFile = split[1], }; foreach(var f in data)...
batch-file,file-rename,batch-rename
This should do what you have described. Remove the echo after the do when you have tested it - atm it will merely print the commands to the screen. @echo off for /f "usebackq tokens=1,*" %%a in ("file.txt") do echo ren "%%a" "%%b" pause ...
bash,shell,scripting,batch-rename
If you want to move the file, you have to use the path, too, otherwise mv wouldn't be able to find it. The target specification for the mv command is more problematic, though. You're using "$fhello.dat" which, in fact, means "content of the $fhello variable plus the string .dat". How...
windows,command-line,file-rename,batch-rename
I don't think you can do this with a single line, you'll need a basic batch file. @echo off setlocal enabledelayedexpansion for %%a in (x_*.*) do ( set fname=%%a set fname=!fname:~2! ren "%%a" "!fname!" ) ...
Set EnableDelayedExpansion then reference the variables with !var! instead of %var% Fixed code: @echo off setlocal EnableDelayedExpansion FOR /L %%G IN (1,1,100) DO ( set num=%%G echo !num! set newnum=0000!num! set newnum=!newnum:~-4! echo !newnum! ren "T%%G.bmp" "T!newnum!.bmp" ) pause endlocal ECHO IS OFF will appear if the variable you are...
batch-file,command-line,rename,file-rename,batch-rename
@echo off setlocal EnableDelayedExpansion rem The list of filenames will be read from redirected Stdin < filenames.txt ( rem Process the files via FOR command for %%a in (*.*) do ( rem Read the next name from the list set /P name= rem Rename the file ren "%%a" "!name!" )...
linux,shell,unix,rename,batch-rename
This is a bit tedious but will do: #!/bin/bash parent=/parent newfolder=/newfolder mkdir "$newfolder" for folder in "$parent"/*; do if [[ -d $folder ]]; then foldername="${folder##*/}" for file in "$parent"/"$foldername"/*; do filename="${file##*/}" newfilename="$foldername"_"$filename" cp "$file" "$newfolder"/"$newfilename" done fi done Put the parent path to parent variable and newfolder path to newfolder...
excel,rename,file-rename,batch-rename
just tested Sub rename_batch() filePath = "C:\tmp\" counter = 0 For Each c In Range(Cells(2, 1), Cells(Rows.Count, 1).End(xlUp)) If Dir(filePath & c.Value) <> "" Then Name filePath & c.Value As filePath & c.Offset(counter, 1).Value c.Offset(0, 2).Value = c.Value & " > " & c.Offset(counter, 1).Value Else counter = counter -...
You can do this: #!/bin/bash find . -name "*A.jpg" | while read f do newname=${f/A.jpg/[email protected]} echo convert "$f" -resize 400x400 "$newname" done Remove the word echo if it looks correct, and run only on files you have backed up. You can also do it in a one-liner, if you really...
windows,windows-7,file-rename,batch-rename
Use a batch file @echo off setlocal enableextensions disabledelayedexpansion cd /d "c:\where\thefiles\are" for /f "tokens=1,2,* delims=#" %%a in (' dir /b /a-d *.pdf ^| findstr /r /b /e /i /c:"[^#][^#-]*#[^#][^#]*#..*\.pdf" ') do echo ren "%%a#%%b#%%c" "%%b#%%a#%%c" What this code does is Get the file list: a dir command asking for...
regex,batch-file,powershell,batch-rename
PowerShell, untested but should work: $filelist = Get-ChildItem C:\folder | Where-Object {$_.Mode -match "a"} ` | Foreach-Object {$_.FullName} foreach ($fullpath in $filelist) { $newpath = $fullpath -replace "_(19|20)[0-9]{6}" Rename-Item -Path $fullpath -NewName $newpath -WhatIf } The _(19|20)[0-9]{6} regular expression matches the following pattern: leading "_" followed by "19" or "20"...
windows,batch-file,file-rename,batch-rename
Use the for command. @echo off set YourFileName=title.s1e2.mp4 for /f "tokens=1 delims=." %%x in ("%YourFileName%") do (set filename1=%%x) for /f "tokens=3 delims=." %%x in ("%YourFileName%") do (set filename2=%%x) echo %filename1%.%filename2% rename C:\PATH\%YourFileName% %filename1%.%filename2% pause>nul This should remove the "s1eNum" in the middle, then combine the file name and the extension...
windows,batch-file,batch-rename
@ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION SET "sourcedir=U:\sourcedir" FOR /f "tokens=2delims=[]" %%a IN ( 'dir /b /a-d "%sourcedir%\[*]*[*].mkv" ' ) DO ( SET "newname=%%a" ECHO(REN "%sourcedir%\[*]%%a[*].mkv" "!newname:~1,-1!.mkv" ) GOTO :EOF This should fix your problem. The required REN commands are merely ECHOed for testing purposes. After you've verified that the commands are...
The Python string method endswith does not do pattern-matching with *, so you're looking for filenames which explicitly include the asterisk character and not finding any. Try using regular expressions to match your filenames and then building your target filename explicitly: import os import re patt = r'RJ_\d\d\d' user_profile =...
linux,bash,media,file-rename,batch-rename
Using a bash script: #!/bin/bash shopt -s extglob for A in *.mp3; do B=${A/%-+([[:alnum:]_]).mp3/.mp3} [[ $A != "$B" ]] && mv "$A" "$B" done That would fix your filenames for files that were already downloaded....
windows,batch-file,command-line,batch-rename
Here is a one liner that does not require delayed expansion. From the command line: for /f "tokens=1* delims=:" %A in ('dir /b^|findstr /n "^"') do @ren "%B" "renamed%A.ren" Within a batch script @echo off for /f "tokens=1* delims=:" %%A in ('dir /b^|findstr /n "^"') do ren "%%B" "renamed%%A.ren" ...
batch-file,backup,batch-rename
@echo off setlocal enableextensions disabledelayedexpansion set "source=%cd%\source" set "target=%cd%\target" for %%a in (DB_Live DB_Test) do ( set "first=1" for /f "delims=" %%b in (' dir /a-d /tw /o-d /b "%source%\%%a_*.bak" ') do if defined first ( set "first=" copy /b /y "%source%\%%~b" "%target%\%%a%%~xb" ) ) For each set of files,...
The for replaceable parameters can include a list of delimiters to extract only part of the content in the case of file/folder references (see for /?) In your case %%~dpnf.pdf will return the drive, path, and name of the input file, with the string .pdf attached. for /f "delims=" %%f...
windows,batch-file,batch-rename
@echo on setlocal EnableDelayedExpansion set a=10001 for /f "tokens=*" %%i in ('dir /b "C:\TEST\PBM\PAR*"') do ( set var1=%%i SET sub1=!var1:~7,22! ECHO !sub1! ECHO ren "%%i" "ABC!sub1!_!a!.dat" set /a a+=1 ) With delayedexpansion any reference to the value of a variable that is changed within the loop must use the !var!...
Try like this : %original:~0,-4%-added.txt ...
The problem is that you're quoting "$(ls -Atr | grep [.]jpg)" so you're getting just a long string with all the filenames. This would be a better attempt: #!/bin/bash read -p "Digit new name (no spaces and special chars!): " newname echo i=0 if test "$(ls -A | grep [.]jpg)";...