REN and MOVE for very long directory and file names exceeding MAX_PATH

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

REN and MOVE for very long directory and file names exceeding MAX_PATH

Post by MigrationUser »

22 Jan 2019 21:06
Commander_Keen


Hi,

I'm trying to batch rename and/or move files which are stored a directory with long path so that path+filename exeed MAX_PATH.

While DEL is documented as being capable of using a syntax like this
DEL "\\?\C:\some long folder\long file name.txt" (ss64.com/nt/del.html)
commands like REN or MOVE are not.
As a lucky shot I tried anyway REN with "\\?\absolute path" and "\\?\.\long filename" but it complained that filename or extension is too long.

1) Where can see which commands support the "\\?\" syntax?
2) How can I rename and/or move such files in a batch?

Thanks for your thoughts.

----------------------------

#2 22 Jan 2019 21:13
Commander_Keen
Commander_Keen wrote:

While DEL is documented as being capable of using a syntax like this
DEL "\\?\C:\some long folder\long file name.txt" [...]
Okay, it seems I'm missing something, DEL also complains about too long path even when using "\\?\C:\long path\to\file.ext".

OS: Win2008 R2

----------------------------

#3 23 Jan 2019 22:47
RG


Take a look here
http://stackoverflow.com/questions/9787 ... 8069#98069

I have done it like this.

Code: Select all

SET "Folder=Your Folder\Structure"
RMDIR /S /Q "%Folder%" 2>nul & REM Delete what we can
MD "%Folder%\Empty"
ROBOCOPY.EXE "%Folder%\Empty" "%Folder%" /MIR >nul & REM Copy the Empty folder with /MIR to wipe out existing stuff
ECHO( >"%Folder%\%~nx0 Deleted Contents Of This Folder" & REM Put indication in folder that we deleted stuff
Windows Shell Scripting and InstallShield

----------------------------

#4 27 Jan 2019 18:45
Commander_Keen


Hum, thanks, but first of all I'd like to rename this file and move it before considering deletion of the whole folder. ;-)
I also would like to achieve that without external programs.
Post Reply