Need to view merged photos directory in date sequence - windows

I have two photo folders taken with different cameras, and want to merge them by date, and then view the combined directory in date sequence. I have merged them, and the directory dates look good, but the tools I use insist of showing the photos in name sequence, which is not what I want. I thought of doing a batch rename function to make the date part of the file names, using a bat file, but the DOS DIR command doesn't seem to use this date - if I do
for /f "skip=5 tokens=1,2,4,5* delims= " %%i in ('dir /a:-d /o:d /t:c') do (
etc., most of the file dates are correct, but some of the files seem to be using the "created date" of the directory.
Maybe there is a simple solution as this must be a common problem, but I haven't found a good solution - short of doing a laborious manual rename of some 700+ files!
Help would be appreciated!
Paul M.

for /f "tokens=1*delims=[]" %%a in ('dir /b /a-d /od /t:c^|find /v /n "" ') do echo ren "%%b" "%%a%%~xb"
Perform a directory scan of the source directory, in /b basic mode /a-d without directories in date order selecting created-date, number in brackets each line that doesn't match an empty string and assign each filename found to %%b and the number to %%a
The required REN commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO REN to REN to actually rename the files.
Note: filenames that begin [ or ] will be processed incorrectly. If an existing file has a name which belongs to the target nameset (ie 1.? 2.? etc.) then simply prefix the target name with a prefix that doesn't already exist, eg ren "%%b" "new_%%a%%~xb" (where there are no existing files named new_*)
I'm not sure about Win7's capability when displaying files using the utility you are using (Explorer?) Win10 has the capability of selecting display by creation-date (select sort by then creation-date)
If you are sure you are sorting by creation-date then probably you'd need to select some other sorting scheme (change t:c to t perhaps)
If there are filenames that aren't being converted, then you are probably adding files (called img*) to a directory that already contains files named 1,2,3... - in fact, it's difficult to see how that phenomenon could happen otherwise.
Change "%%a%%~xb" in the rename command to "xyz%%a%%~xb" and you should find that the files are then all renamed xyz1,xyz2,xyz3 etc. If you then reprocess the files with xyz removed, the names should become 1,2,3 with no omissions.

Related

How can I remove a specific part of many folders names using .bat files?

My university is using a proprietary system that outputs data in a very specific way in which each "module" is output into folders following the structure (4 digit numeral) - (name of module)
ex: 5574-CHEM104
I need to remove the name and hyphen so that only the numeral remains:
5574-CHEM104 > 5574
The problem is that there's thousands of these folders and there's no way I could do it by hand. I'm having difficulty trying to automate the process, so if anyone could at least point out a command I could look into it would help immensely
I've tried the REN command, putting "REN 5574-CHEM104 5574", but it only works for one folder. There's thousands of folders, each with different numerals, under "CHEM104", for example, and I need for the program to rename the folder no matter the original name into the first 4 original numerals, which I can't figure out. Thanks!
#ECHO OFF
SETLOCAL
rem The following setting for the directory is a name
rem that I use for testing and deliberately includes spaces to make sure
rem that the process works using such names. These will need to be changed to suit your situation.
SET "sourcedir=u:\your files"
FOR /f "delims=" %%e IN (
'dir /b /ad "%sourcedir%\*" '
) DO FOR /f "delims=-" %%o IN ("%%e") DO ECHO REN "%sourcedir%\%%e" "%%o"
)
GOTO :EOF
Always verify against a test directory before applying to real data.
The required REN commands are merely ECHOed for testing purposes. After you've verified that the commands are correct, change ECHO REN to REN to actually rename the directories.
Using a list of the directory-names, names only (/b) and directories only (/ad), tokenise the name using - as a delimiter and execute the rename using the token assigned to %%o (default is first token)

Batch script to read numerical part of file and rename with next higher integer

I have a file, such as -
foofile_1.ext
A script should read the numerical part of the file, and then rename the file with the next integer, i.e., after execution, the file name should be
foofile_2.ext
I can do it with a C++ / c application or even in bash but not sure how to write a batch script to perform this rename. The filename before the _ isn't going to change, and _ will aaways appear in the same position within the filename.
I can strip the filename to _, but recognizing the numerical is an implementation I am not familiar with. Once I recognize the numerical, I can increment it and rename the file.
Something to consider is that renaming foofile_1.ext to foofile_2.ext will fail should foofile_2.ext already exist. One way to get around it is to rename in descending numerical order, I posted an answer like that before on SO.
I am however not going to post the same answer here, nor link that answer. I will however show one other method:
#echo off
setlocal enabledelayedexpansion
for /f "tokens=1,*delims=_" %%i in ('dir /b /a-d "*_*.ext"') do (
echo %%~nj | findstr /R /V /C:"[A-Z]">nul && (
set /a numeric=%%~nj+1
ren "%%~i_%%~j" "%%~i_-hld-!numeric!%%~xj"
)
)
for /f "delims=" %%f in ('dir /b /a-d "*_-hld-*.ext"') do (
set "name=%%~f"
ren "%%~f" !name:-hld-=!
)
Considering that your input is as you said and does not contain earlier _'s anywhere. This will just take each file with the *_*.ext format. We split by the _ into two tokened metavaiables (%%i and %%j) We take the numeric value and increment by one, then rejoin %%i which is pre _. This however is where the problem comes when the file you are trying to rename to exists, so for that, first we test if %%~nj does not have Alphabetical characters only, using findstr (not doing special characters in this free code) Secondly we give a temporary addition to the name to prevent name clashing.
Once we are done, we simply do a rename on all the files containing the _-hld- temp inclusion.

Batch renaming files after certain character

I have a bunch of video files with names like so:
6592110904-Ivory-2.mp4
6592280588-Cornflower.mp4
6592321696-Ballet Pink.mp4
I want to rename them to get rid of everything after the first hyphen so they end up like:
6592110904.mp4
6592280588.mp4
6592321696.mp4
How do I go about doing this?
Please put the code below in a bat file, place it in directory with mp4 files. Before running real renaming, please remove "echo" before "move". please be carefull with renaming bacause (theoretically) it is possible to have same name for different files.You'll be prompted to confirm if you want to override the old one.
Code splits each filename after dash and renames the file taking first item. Good luck.
#echo off
for /F "tokens=1,* delims=-" %%a in ('dir /A-D /B "*.mp4"') do (
echo move "%%a-%%b" "%%a%%~xb"
)

Windows batch file loop running one extra iteration [duplicate]

This question already has an answer here:
At which point does `for` or `for /R` enumerate the directory (tree)?
(1 answer)
Closed 3 years ago.
I'm using a windows batch file to rename a very large number of files in one go. The renaming simply adds a prefix to the file name. The file executes fine except for the last file, to which the prefix is somehow applied twice. I'm not sure what I'm doing wrong. Can anyone point out the problem to me?
for %%i in (*.csv) do ren %%i myprefix_%%i
#echo off
SETLOCAL
DEL *.csv
XCOPY ..\*.csv .
(
for %%i in (*.csv) do (
echo ====================
echo %%i
dir *.csv
ren %%i x%%i
dir *.csv
echo ====================
)
)>u:\junk.txt&edit u:\junk.txt
I ran the above batch in a clean directory below a directory that contained a few .CSVs. All it does is zap the current directory's .csvs, copy those from the parent directory and then rename by prefixing. It revealed quite a bit.
(U: is a RAMDRIVE, EDIT executes EDITPLUS; NOTEPAD would do as well here)
The operation depends on quite what prefix is added. A prefix starting "a" works differently from a prefix starting "x". AND the result depends on the filesystem being used. NTFS presents the filenames alphabetically but the FAT system on the RAMDRIVE doesn't sort the names.
I believe the problem is caused by the 'findnext' filename mechanism not dealing as expected with a changing list of filenames. As it changes one, that name may move in the list and hence the file may be reprocessed as its new name is encountered again - possibly multiple times.
A cure is to replace the for selection with
for /f "delims=" %%i in ('dir /b *.csv') do (
where the DIR list is created and THEN processed, so the changes don't affect it.
You may be having some spaces in your filenames. Use double-quotes around filenames. Try the following:
for %%i in (*.csv) do ren "%%I" "myprefix_%%I"
This will execute as:
ren "tmp - Copy.csv" "myprefix_tmp - Copy.csv"
Also, you should look for any hidden files.

How to rename and add incrementing number suffix on multiple files in Batch Script?

I have 500 files coming in and I need to first check if any file(s) exist then rename all of them regardless of what their filename is (the files are named in a different language).
No need to process them in any order.
Rename:
1. “¦X¼d¬f-20110703-¦+¦dñHÑ-ª-¦=¬¦.xls”
2. “¦X¼d¬f-20110707-¦+¡¦-+¡8.xls”
3. “¦X¼d¬f-20110707-¦+¡¦ñj¦«.xls”
4. “¦X¼d¬f-20110708-¦+¡¦¬M¼n.xls”
5. “¦X¼d¬f-20110713-¦d¼O¼n¦hÑP.xls”
.
.
.
500
To:
“TWN_CH_INV_VISIT_FORM_01.xls”
“TWN_CH_INV_VISIT_FORM_02.xls”
“TWN_CH_INV_VISIT_FORM_03.xls”
“TWN_CH_INV_VISIT_FORM_04.xls”
“TWN_CH_INV_VISIT_FORM_05.xls”
.
.
.
“TWN_CH_INV_VISIT_FORM_500.xls”
Hope you could help me on this one. I’ve been trying to do this for weeks.
a simple FOR with a count (SET /A) should do what you need.
setlocal enabledelayedexpansion
SET /A COUNT=0
FOR %%A IN (*.xls) DO (
SET /A COUNT+=1
REN "%%A" "TWN_CH_INV_VIST_FORM_!COUNT!.xls"
)
See HELP FOR and HELP SET
This is a deceptively difficult question to solve.
The 5 year old PA answer has a few problems.
1) The FOR loop begins iterating without buffering the entire directory tree, so it has the potential to rename a file that has already been renamed. I believe that is why the 7 file is missing within r0mmel's comment.
2) Delayed expansion occurs after for variables are expanded, so the file name will be corrupted and the rename will fail if the name contains a ! character.
3) A rename can fail if there already exists a TWN_CH_INV_VIST_FORM_n.xls file with the same number.
At first I thought I could solve the problem using the following:
#echo off
for /f "delims=: tokens=1*" %%A in (
'dir /b *.xls ^| findstr /n "^"'
) do ren "%%B" "TWN_CH_INV_VIST_FORM_%%A.xls.new"
ren *.txt.new *.
I use DIR /B to list the files, and pipe that result to FINDSTR to prefix each file name with a line number, followed by a colon.
I then use FOR /F to iterate and parse the results into the number and the file name. FOR /F buffers the entire result before iterating, so I don't need to worry about renaming the same file twice.
I first give the renamed files a .xls.new "extension", just in case your directory already has files that meet the TWN_CH_INV_VIST_FORM_n.xls pattern. You don't want any name collisions. The final REN command then simply removes the .new extension to leave the desired .xls.
BUT, I just noticed that the original file names have lots of weird characters that could involve unicode that is not in the current code page. FOR /F does not play well with unicode.
There is one other minor issue in that the above does not pad the number to a fixed width. (this could have been solved easily enough)
So at this point it is time to break out my JREN.BAT regular expression renaming utility. It is pure script (hybrid batch / JScript) that runs natively on any Windows machine from XP onward. It has a built in facility to incorporate a fixed width incrementing number in the new name, and it works fine with unicode. I still temporarily give the new name the ".xls.new" extension to avoid any name collisions.
#echo off
call jren "^.*" "'TWN_CH_INV_VIST_FORM_'+$n+'.xls.new'" /j /npad 3 /fm *.xls
ren *.xls.new *.
I chose to pad the incrementing number to 3 digits instead of 2 because the OP said there could be 500 files.
Full documentation for JREN.BAT is available from the command line via jren /?, or jren /?? if you want paged output.

Resources