I am trying to rename files using Windows CMD from file naming data-001.wav data-002.wav to input-001.wav input-002.wav replacing the word data to input in the file names.
I tried: ren data-*.wav input-*.wav but getting input-01.wav input-02.wav instead of input-001.wav input-002.wav the numbering digits are not matching the file names correctly.
Related
I need to rename a group of .pdf files
In the \Source folder I have the files:
bbbbbbbbb-56.pdf
vduysdvss-60.pdf
sdvbdsbvv-80.pdf
I have to rename them in the \Destination folder like this:
11111111-bbbbbbbbb-ggg-hhh-56-dddd.pdf
11111111-vduysdvss-ggg-hhh-60-dddd.pdf
11111111-sdvbdsbvv-ggg-hhh-80-dddd.pdf
so I need to insert some fixed parts:
before the name
in the middle of the name
at the end of the name.
Using the command:
cd \Source
copy "\Source" "\Destination"
cd \Destination
ren *.pdf 11111111-?????????-ggg-hhh???-dddd.*
the result is:
11111111--56-ggg-hhh-dddd.pdf
the bbbbbbbbb string disappears
can you help me?
Thanks
By using the following command Copy the files from Source to Destination :
copy "/Source_folder" "/Destination_folder"
Go in /Destination folder
cd "/Destination_folder"
And then ren the file names by the following command :
ren *.pdf ???-new_filename_part.*
(The question mark (?) is also a wildcard, but it represents a character of the original file name. So, in the syntax, we're using three question marks, which means that the output file name will include the first three characters of the original file (which works as a unique identifier to avoid duplication)
(According to your logic you can change the new filenames by using some RegExpressions or some variables)
I'm having issues renaming the following file using a batch (.bat) file. I'm using Windows 7.
Here's my syntax:
SET MY_PATH=%~dp0
ren %MY_PATH%\MY_RECAP* DBS.txt
I'm attempting to rename a file that has a changing file name due to the current date being appended to the end of the MY_RECAP file name (such as MY_RECAP_MMDDYYYY). I'm using a wildcard to rename that file to DBS.txt
This still won't work. Any ideas?
There are quite many solutions to do this. The first and easier one is:
#ren "%~dp0MY_RECAP_*" "DBS.txt"
If you want to check a DBS.txt file already exists, use an if exist statement:
#if not exist "%~dp0DBS.txt" (#ren "%~dp0MY_RECAP_*" "DBS.txt")
An additional note: If in your batch file you have specified somewhere above #echo off or echo off, remove the # symbols from everywhere.
I'm trying to delete some files in a WinRar Archive using the Command Line.
The Rar-File:
/testing.rar
/testing.rar/some-data.txt
/testing.rar/testing/some-data.txt
Here's my Code:
cd "C:\Program Files\WinRAR\" && rar d -cl -r "c:\full\path\testing.rar" some-data.txt
It only deletes the some-data.txt file in the root, not inside /testing/
When using
cd "C:\Program Files\WinRAR\" && rar d -cl -r "c:\full\path\testing.rar" some-data.*
(changed the extension to .*) it does delete both files.
Am I doing something wrong?
I looked on first version of great solution of MC ND and thought by myself what happens if there is by chance although very unlikely a directory with name some-data.txt inside the archive?
The answer is that this directory with all files and subdirectories is also deleted because of also listed by Rar.exe and findstr does not filter out the list entry of the directory as it looks like exactly like a file name entry in bare list format.
The solution for code written by MC ND is to use the Rar command lb with switch -ed to filter out directory entries on list output. This small modification was applied to the command line by MC ND in his answer.
Then I thought about using the switches -ed and -x"..." to filter out directories and file names which should not be deleted on running Rar.exe with command d and a some-data.txt wildcard pattern.
And here is the single line solution:
"C:\Program Files\WinRAR\Rar.exe" d -ed -x"some-data.txt?*" -- "C:\full\path\testing.rar" "some-data.txt*"
The asterisk at end of file name is necessary to delete all files with name some-data.txt inside the archive including the files in subdirectories.
The switch -ed excludes all directories in archive including those which by chance are named some-data.txt. Directories in archive starting with some-data.txt and with more characters appended like a directory with name some-data.txt_dirare automatically ignored by Rar.exe with used file name wildcard pattern.
The switch -x"some-data.txt?*" results in excluding files starting with some-data.txt and having more characters appended like some-data.txt1 and some-data.txt10. File names like first_some-data.txt are automatically ignored by Rar.exe with used file name wildcard pattern.
The switch -cl to convert file names to lower case is ignored by Rar on using command d and therefore not used in the command line above. Rar interprets the file names case-insensitive like Windows.
Update:
Eugene Roshal, owner of win.rar GmbH, told me by email an easier method to delete a file in root archive folder and in all subfolders:
"C:\Program Files\WinRAR\Rar.exe" d "C:\full\path\testing.rar" "some-data.txt" "*\some-data.txt"
This command line deletes only some-data.txt in root archive folder (last but one argument) and in all its subfolders (last argument). Files in a folder with name some-data.txt are not deleted by this command line, but an empty folder with name some-data.txt would be also removed from archive. The switch -ed can be used additionally to prevent deletion of an empty folder some-data.txt.
While the d command can not handle it, a simple pipe can deal with it
#echo off
setlocal enableextensions disabledelayedexpansion
set "rar=C:\Program Files\WinRar\rar.exe"
set "archive=c:\full\path\testing.rar"
(
%= List archive contents =%
"%rar%" lb -ed "%archive%"
)|(
%= filter the list for the file in any subfolder =%
findstr /i /e /l /c:"\somedata.txt"
%= and include the root file =%
echo somedata.txt
)|(
%= Delete from archive the list of files read from stdin =%
"%rar%" d -cl -n# "%archive%"
)
The second step (filter the list of files in archive) is splited in the findstr and the echo just to prevent the case when the file to be deleted is not present in the output. Without a list of files the -n# modifier (read files to delete from stdin) will not read anything and all the archive contents will be removed.
When I run this file:
xcopy .\*.odt .\source.zip
I am prompted to specify what source.zip is:
xcopy .\*.odt .\source.zip
Does .\source.zip specify a file name
or directory name on the target
(F = file, D = directory)?
In my case when it find the .odt file to copy the file and place in the same directory but with new name source.zip. Is there approach to avoid the prompting since I always want destination to be a file not directory.
Any .odt file (being in .zip format in fact) is a binary file, see OpenDocument Document Representation
As a collection of several sub-documents within a package, each of which stores part of the complete document. This is the common
representation of OpenDocument documents. It uses filename extensions
such as .odt, .ott, .ods, .odp ... etc. The package is a
standard ZIP file with different filename extensions and with a
defined structure of sub-documents. Each sub-document within a package
has a different document root and stores a particular aspect of the
XML document. All types of documents (e.g. text and spreadsheet
documents) use the same set of document and sub-document definitions.
Therefore, you need to treat it as a binary file (read copy /?):
copy /B .\*.odt .\source.zip
Above command would work smoothly only if there will be only one file with extension .odt. Otherwise, it will prompt you for Overwrite .\source.zip? (Yes/No/All):. To stay on the safe side:
from command line for %G in (.\*.odt) do copy /B "%G" ".\source_%~nG.zip"
from a batch script for %%G in (.\*.odt) do copy /B "%%G" ".\source_%%~nG.zip"
%~nG (or in batch %%~nG) explanation: read Parameter Extensions.
I'm trying to rename files that have '#' to '_'.
I understand that there is a straigt forward way of replacing the nth character in a file.
How do we rename files , if # symbol is present in different places in different files
For example, assuming the below files are present in a directory
a#file.txt
asdf#kfi.png
uiuydfjfk#kdi.txt
I want the output to be like this one
a_file.txt
asdf_kfi.png
uiuydfjfk_kdi.txt
Is there anyway to accomplish this ?
This uses a helper batch file called repl.bat from - http://www.dostips.com/forum/viewtopic.php?f=3&t=3855
It creates renfile.bat for you to examine for errors, and then execute.
dir *#* /b |repl "(.*)(#)(.*)" "ren \x22$&\x22 \x22$1_$3\x22" x >renfile.bat