0

Problem

I'm trying to move a folder (ex. \\myUNC\folder1) and its contents to another folder (ex. \\myUNC\Parent\folder1). There are two easy enough ways I'd typically do this - either using move (similar to here) or using ren (similar to here).

Example Code

set oldPath=\\myUNC\folder1
set newPath=\\myUNC\Parent\folder1
move "%oldPath%" "%newPath%"
::ren"%oldPath%" "%newPath%"

Troubleshooting

When attempting the move solution in my first like, I get the error:

The filename or extension is too long. 0 dir(s) moved.

As a result, I tried ren like in my second link, which gave the error:

The syntax of the command is incorrect.

For this second error, I'm assuming that is because I'm passing the path as part of my variable - which ren doesn't accept. The batch calling this change is NOT in the same directory as the folder or its new path. As a result I can't use current directory code (like ren or cd), at least as far as I know.

If anyone has a possible solution it would be greatly appreciated! Thanks.

Community
  • 1
  • 1
TMY
  • 471
  • 1
  • 7
  • 20
  • 1
    `ren` or `rename` just does what it says: renaming files; so you cannot use it for moving files... anyway, try with [`robocopy`](http://ss64.com/nt/robocopy.html)... – aschipfl Aug 24 '16 at 21:18

2 Answers2

1

The filename or extension is too long. 0 dir(s) moved.

This error refers to a 'feature' in Windows that limits file names to a maximum of 255 characters. To overcome this, you would need to shorten the names of the folders on the Network drive.
See Maximum filename length in NTFS (Windows XP and Windows Vista)?

The syntax of the command is incorrect.

This error occured because you cannot state a new folder for the ren command. A file can only be renamed in the same folder, not even subdirectories are allowed. But the reason why you got The syntax of the command is incorrect. error, is because you left out a space in between the ren and the "


Possible solution:

Depending on your scenario, you might be able to pushd into the folder and then use the move command. In my experience, some commands don't respond equally to UNC locations vs local file locations (ex. if exist "\\UNC\"):

@echo off
pushd \\myUNC\
set oldPath=folder1
set newPath=Parent\folder1
move "%oldPath%" "%newPath%"
popd

This will only work though, if you haven't exceeded the 255 char limit

Community
  • 1
  • 1
Sam Denty
  • 3,693
  • 3
  • 30
  • 43
  • Unfortunately the pushd solution didn't work. I've found an alternative solution using `robocopy` however. – TMY Aug 25 '16 at 15:33
0

After a lot of troubleshooting, I was able to find a solution with no errors!

Solution

set oldPath=\\myUNC\folder1
set newPath=\\myUNC\Parent\folder1
robocopy /move "%oldPath%" "%newPath%"

Why

Robocopy is a newer command from Microsoft, and accounts for filename strings longer than 256 characters (apparently the issue with move and/or copy command).

You can google robocopy to learn more about the command options and parameters, but its fairly straight forward. For my issue, I wanted to move the file, so I just used the /move option, which deletes the original folder and files.

TMY
  • 471
  • 1
  • 7
  • 20