Renaming Folder with RenameItem - Access Denied
Renaming Folder with RenameItem - Access Denied
Yup, not sure what the problem is. I renamed a child folder just fine. But when renaming the parent folder, it refuses. There is nothing accessing the disk other than XYplorer. I'm replacing "." with "_" and it works fine with the child folder. And the parent is a child of still another folder. So it makes no sense that one can be renamed but not the other. Im using ver14.3. Is it an upgrade problem? I've had this ver for awhile and it works fine except for this hicup.
e:\test\All.the.Old.Knives.2022 2160p AMZN WEB-DL DDP5-1 HDR HEVC-CMRG[TGx]\1BR.2019.1080p.WEB-DL.H264.AC3-EVO[TGx] ----- Original
e:\test\All.the.Old.Knives.2022 2160p AMZN WEB-DL DDP5-1 HDR HEVC-CMRG[TGx]\1BR_2019_1080p_WEB-DL_H264_AC3-EVO[TGx] ----Success
e:\test\All.the.Old.Knives.2022 2160p AMZN WEB-DL DDP5-1 HDR HEVC-CMRG[TGx] ------ Access Is Denied
$output = renameitem($newname, $itm, 1+2+4);
error message:
Access is denied.
renameitem()
All_the_Old_Knives_2022 2160p AMZN WEB-DL DDP5-1 HDR HEVC-CMRG[TGx]
E:\test\All.the.Old.Knives.2022 2160p AMZN WEB-DL DDP5-1 HDR HEVC-CMRG[TGx]
7
Anybody see any reason why this does not work? I rebooted my PC and didn't run anything else, and I still get this failure.
Thanks for your interest.
e:\test\All.the.Old.Knives.2022 2160p AMZN WEB-DL DDP5-1 HDR HEVC-CMRG[TGx]\1BR.2019.1080p.WEB-DL.H264.AC3-EVO[TGx] ----- Original
e:\test\All.the.Old.Knives.2022 2160p AMZN WEB-DL DDP5-1 HDR HEVC-CMRG[TGx]\1BR_2019_1080p_WEB-DL_H264_AC3-EVO[TGx] ----Success
e:\test\All.the.Old.Knives.2022 2160p AMZN WEB-DL DDP5-1 HDR HEVC-CMRG[TGx] ------ Access Is Denied
$output = renameitem($newname, $itm, 1+2+4);
error message:
Access is denied.
renameitem()
All_the_Old_Knives_2022 2160p AMZN WEB-DL DDP5-1 HDR HEVC-CMRG[TGx]
E:\test\All.the.Old.Knives.2022 2160p AMZN WEB-DL DDP5-1 HDR HEVC-CMRG[TGx]
7
Anybody see any reason why this does not work? I rebooted my PC and didn't run anything else, and I still get this failure.
Thanks for your interest.
-
WirlyWirly
- Posts: 274
- Joined: 21 Oct 2020 23:33
- Location: Win 10 @ 100% (3440x1440)
Re: Renaming Folder with RenameItem - Access Denied
You might try the free tool iobit unlocker, which will check for any processes accessing the file/folder and attempt to free them.
Also, check your permissions, it may have somehow been set to read only.
if you can still rename it with Windows Explorer or another tool, that would narrow it down to being an xy issue.
Also, check your permissions, it may have somehow been set to read only.
if you can still rename it with Windows Explorer or another tool, that would narrow it down to being an xy issue.
Re: Renaming Folder with RenameItem - Access Denied
So in case there were invisible attribute access issues, I created another test directory on another drive and got the very same results. Access denied. I typed that script command by hand just as it is without any other code and the directory was renamed without any problem. So there is nothing funny about drive access. So that output command is within a "Foreach" loop that updates $Itm on each iteration. So the use of the Foreach command must close out access rights so that RenameItem is unable to function. So it looks like my only other idea is to rewrite that loop without using the Foreach command. I have not downloaded the free tool to find who is hogging access, but by process of elimination, it looks pretty clear that Foreach must be used carefully.
Re: Renaming Folder with RenameItem - Access Denied
Try to step through your script to see what names it actually processes when it fails.
Ralph 
(OS: W11 24H2 Home x64 - XY: Current x32 beta - Office 2024 32-bit - Display: 1920x1080 @ 125%)
(OS: W11 24H2 Home x64 - XY: Current x32 beta - Office 2024 32-bit - Display: 1920x1080 @ 125%)
Re: Renaming Folder with RenameItem - Access Denied
Ok, did a little more with it. RenameItem within a Foreach loop only accesses the very last directory in any path. I made more test directories with very simple names and got the same access denial failure. So it's not a funny character issue. I have code that parses out the directories individually so they can be renamed individually. And the parsing only crunches on character string copies, not hogging access to the drive while the crunching occurs. And the crunching works well to identify and rename the text strings of each directory that I want renamed. It's just the actual renaming that only works part of the time. I then inserted an if else test for the case when it gets to the first directory that it's unable to rename. Instead of passing the calculated strings to the Renameitem function, I instead simply type the directory and the change I desire in quotes. Else use the calculated strings. And the calculated strings succeed on the last directory in the path, but the hand typed string fail on the next to last directory in the path. So it has nothing to do with some error in the strings. It wont even work with text in quotes. So the problem is in the microcode that makes RenameItem function within the Foreach loop. I even used a dummy variable set equal to the strings that Foreach returned. That way Rename Item was not even using the same variable. And it still failed. So I will have to write a home made Foreach loop. Unless this was somehow fixed in the new version. Ill just write code and see if I can just fix this quick. I wouldn't have spent this long on it, but this was a mind twisty kind of problem. The step mode shows all the variables, so everything looks great until that write function is executed. So Ill just have to code around it.\
Update. I replaced Foreach with a while loop, Gettoken and counters. All the variable function perfectly. But I still got the same problem. The farthest child directory renames but none of the others all the way to the root. So Foreach is not messing RenameItem up. Rename is simply broke on it's own. I can hand type it to execute all by itself, but it won't function properly surrounded by other code. That is one strange head twister. Access Denied.
Update. I replaced Foreach with a while loop, Gettoken and counters. All the variable function perfectly. But I still got the same problem. The farthest child directory renames but none of the others all the way to the root. So Foreach is not messing RenameItem up. Rename is simply broke on it's own. I can hand type it to execute all by itself, but it won't function properly surrounded by other code. That is one strange head twister. Access Denied.
Re: Renaming Folder with RenameItem - Access Denied
Post the script?
One of my scripts helped you out? Please donate via Paypal
Re: Renaming Folder with RenameItem - Access Denied
Reposted below...
Last edited by stts1 on 26 Jan 2025 18:38, edited 1 time in total.
Re: Renaming Folder with RenameItem - Access Denied
Embed it in code tags^^
One of my scripts helped you out? Please donate via Paypal
Re: Renaming Folder with RenameItem - Access Denied
Oh yuck. Code doesn't post very pretty here. Anyways, I'm making progress. The whole thing works ONCE. Then all the directories is accessed are left locked. So It doesn't work again without running that IOBit Unlocker tool. Not sure why all the directories are left locked. I been renaming folders only for now. But I have renamed all files before on a different drive. The point is to rename to anything I want. And what I do is shorten paths by eliminating worthless tags in all the names. But it's buggy now, so I don't rename anything till all the bugs are worked out. Not sure if it's a windows 7 problem or what.
Code: Select all
setting "BackgroundFileOps", 0;
$RootFolder = inputfolder(<curpath>, "Pick root folder to start ALL renaming, root folder IS also renamed");
$type = inputselect("Choose if you want to rename files, folders or both. ", "Files ( All files from the Root down)|Folders (From the Root to the Chosen Child inclusive)|Files & Folders", "|", 4+32+128, , 450, 300);
if (($type == 1) or ($type == 2))
{
$ChildDepth = input("Type child folder depth to stop renaming directories inclusive.", "Enter value, 0 or ENTER renames root and all child directories.", "0", "s", 0, 250, 150);
}
$RootDepth = gettoken($RootFolder, "count", "\");
$countAllFiles = 0;
$countAllDirs = 0;
$patterns = input("Enter the string to remove", "Optionally enter a replacement: string/replace. Suffix \ to replace case-sensitively, eg.: StR/RepLaCe\<crlf 2> Separate additional patterns with a | character", ,"w", ,1050);
if ($patterns) //if a pattern was entered then do.
{
$count = 0;
$unrenamedItems = "";
if (($type == 0) or ($type == 2))
{
$Filelst = formatlist(folderreport('files', 'r', $RootFolder, 'r', , '|'), 'v', '|'); //Make a string of every file then invert Filelist so deeper folders are processed first
$countAllFiles = gettoken($Filelst, "count", "|"); //Count all Files in the File list
foreach ($itm, $Filelst, '|') //Do this for each file in the file list and set $itm to next succesive file.
{
$oldname = gettoken(regexreplace($itm, "(.*)(\.[^.]+$)", "$1"), -1, '\'); //Set $oldname to a single file reading right to left.
$newname = $oldname;
foreach($pattern, $patterns, "|") //Do this for each pattern in the pattern list and set $pattern to next succesive pattern.
{
$remstr = gettoken($pattern, 1, '/'); //Set $remstr to part of pattern to be removed.
$rplstr = gettoken($pattern, 2, '/'); //Set $rplstr to part of pattern to be inserted.
$newname = replace($newname, $remstr, $rplstr); //Replace all matching strings to make new name.
}
if ($newname != $oldname)
{
$output = renameitem($newname, $itm, 1+4); //Rename file, base only, prompt on name-collision
if !($output) { $unrenamedItems = $unrenamedItems . "$itm<crlf>"; }
else { $count++; }
}
}
}
if (($type == 1) or ($type == 2))
{ //Make a string of every folder then invert Dirlist so deeper folders are processed first, root folder is included.
$DirList = formatlist(folderreport('dirs', 'r', $RootFolder, 'r', , '|'), 'v', '|'); //This works on Networked drives just fine. The counts are simply bumped up abit but are still relative to each other.
if ($DirList) {$DirList = $DirList.'|'.$RootFolder ;} //Add root folder to end of DirList. Inclusive of parent folder but not twice for case of no subfolder.
else {$DirList = $RootFolder ;} // else DirList IS root folder.
$countAllDirs = gettoken($DirList, "count", "|"); //Count all Dirs in the directory list
foreach ($itm, $DirList, '|') //Do this for each path in the directory list and set $itm to next succesive path string.
{
$FolderDepth = gettoken($itm, "count", "\");
if (($RootDepth) >= ($FolderDepth - $ChildDepth)) or ($ChildDepth == 0) // Rename folders down to childDepth or rename ALL folders.
{
$oldname = gettoken($itm, -1, '\'); //Set $oldname to a single path reading right to left.
$newname = $oldname;
foreach($pattern, $patterns, "|") //Do this for each pattern in the pattern list and set $pattern to next succesive pattern.
{
$remstr = gettoken($pattern, 1, '/'); //Set $remstr to part of pattern to be removed.
$rplstr = gettoken($pattern, 2, '/'); //Set $rplstr to part of pattern to be inserted.
$newname = replace($newname, $remstr, $rplstr); //Replace all matching strings to make new name.
}
if ($newname != $oldname)
{
$output = renameitem($newname, $itm, 1+2+4); //Rename folder, base and extention, prompt on name-collision
if !($output) { $unrenamedItems = $unrenamedItems . "$itm<crlf>"; }
else { $count++; }
}
}
}
}
#1001; //refresh
$message = ($unrenamedItems) ? "<crlf 3>These items could not be renamed:<crlf 2>$unrenamedItems" : "";
text "Items renamed: $count of ($countAllFiles Files + $countAllDirs Folders)$message";
}
Last edited by stts1 on 27 Jan 2025 11:54, edited 1 time in total.
Re: Renaming Folder with RenameItem - Access Denied
01. Begin the script with:
02. The
03. Show a demo folder structure (with the least amount of files / folders) wich which your script fails so that it can be reproduced
E.g.:
setting "BackgroundFileOps", 0;02. The
text ... line at the end does NOT have the stringThese items could not be renamed: in it after running it?03. Show a demo folder structure (with the least amount of files / folders) wich which your script fails so that it can be reproduced
E.g.:
Code: Select all
D:\test
D:\test\sub1
D:\test\sub1\file1.txt
D:\test\sub2
D:\test\sub2\file2.txtOne of my scripts helped you out? Please donate via Paypal
Re: Renaming Folder with RenameItem - Access Denied
These line strings below are text items to change or remove from file names to shorten them. Make changes to both files and folders.
Copy Paste each line of items one line at a time into XYplorers "enter String to remove" scrypt prompt and press ok to execute one line at a time.
Turn off wordwrap in notepad or some items in each line could be randomly skipped.
--------------------------------------------------------------------------------------------------------------------------
2.0/2-0|5.1/5-1|6.1/6-1|7.1/7-1
./ | /
(@btnet)/|@btnet/|@btnet/|[tgx]/|[rarbg]/|()/| [sharethefiles com]/
(1)/|(2)/|(3)/|(4)/|(5)/|(6)/|(7)/|(8)/|(9)/|(10)/|(11)/|(12)/|(13)/|(14)/|(15)/
Copy Paste the year string with Notepad wordwrap OFF or some years will be skipped.
2025/(2025)|2024/(2024)|2023/(2023)|2022/(2022)|2021/(2021)|2020/(2020)|2019/(2019)|2018/(2018)|2017/(2017)|2016/(2016)|2015/(2015)|2014/(2014)|2013/(2013)|2012/(2012)|2011/(2011)|2010/(2010)|2009/(2009)|2008/(2008)|2007/(2007)|2006/(2006)|2005/(2005)|2004/(2004)|2003/(2003)|2002/(2002)|2001/(2001)|2000/(2000)|1999/(1999)|1998/(1998)|1997/(1997)|1996/(1996)|1995/(1995)|1994/(1994)|1993/(1993)|1992/(1992)|1991/(1991)|1990/(1990)|1989/(1989)|1988/(1988)|1987/(1987)|1986/(1986)|1985/(1985)|1984/(1984)|1983/(1983)|1982/(1982)|1981/(1981)|1980/(1980)|1979/(1979)|1978/(1978)|1977/(1977)|1976/(1976)|1975/(1975)|1974/(1974)|1973/(1973)|1972/(1972)|1971/(1971)|1970/(1970)|1969/(1969)|1968/(1968)|1967/(1967)|1966/(1966)|1965/(1965)|1964/(1964)|1963/(1963)|1962/(1962)|1961/(1961)|1960/(1960)|1959/(1959)|1958/(1958)|1957/(1957)|1956/(1956)|1955/(1955)|1954/(1954)|1953/(1953)|1952/(1952)|1951/(1951)|1950/(1950)|1949/(1949)|1948/(1948)|1946/(1946)|1942/(1942)|1939/(1939)|1938/(1938)|1935/(1935)|1927/(1927)
((/(|))/)
-------------------------------------------------------------
Execute these lines on the ROOT directory only to shorten long directory paths.
bluray| bdrip| brrip| 720p| 1080p| 2160p| DTS-HD MA| DTS-HD| TrueHD| DTS-X-HD| DD| x264| h264|-1-0| 1-0|1-0|-2-0| 2-0|2-0|-4-0| 4-0|4-0|-5-1| 5-1|5-1|-6-1| 6-1|6-1|-7-1| 7-1|7-1| atmos| Atm|Directors Cut/DC
-------------------------------------------------------------
So when I pump all these lines into this script, All my files and directories are really left cleaned up. Junk is removed, all years have brackets, and all double stuff is removed. And I will add more stuff to these lines as I see what is left. I have 100,000 files that benefit from this cleaning.
Copy Paste each line of items one line at a time into XYplorers "enter String to remove" scrypt prompt and press ok to execute one line at a time.
Turn off wordwrap in notepad or some items in each line could be randomly skipped.
--------------------------------------------------------------------------------------------------------------------------
2.0/2-0|5.1/5-1|6.1/6-1|7.1/7-1
./ | /
(@btnet)/|@btnet/|@btnet/|[tgx]/|[rarbg]/|()/| [sharethefiles com]/
(1)/|(2)/|(3)/|(4)/|(5)/|(6)/|(7)/|(8)/|(9)/|(10)/|(11)/|(12)/|(13)/|(14)/|(15)/
Copy Paste the year string with Notepad wordwrap OFF or some years will be skipped.
2025/(2025)|2024/(2024)|2023/(2023)|2022/(2022)|2021/(2021)|2020/(2020)|2019/(2019)|2018/(2018)|2017/(2017)|2016/(2016)|2015/(2015)|2014/(2014)|2013/(2013)|2012/(2012)|2011/(2011)|2010/(2010)|2009/(2009)|2008/(2008)|2007/(2007)|2006/(2006)|2005/(2005)|2004/(2004)|2003/(2003)|2002/(2002)|2001/(2001)|2000/(2000)|1999/(1999)|1998/(1998)|1997/(1997)|1996/(1996)|1995/(1995)|1994/(1994)|1993/(1993)|1992/(1992)|1991/(1991)|1990/(1990)|1989/(1989)|1988/(1988)|1987/(1987)|1986/(1986)|1985/(1985)|1984/(1984)|1983/(1983)|1982/(1982)|1981/(1981)|1980/(1980)|1979/(1979)|1978/(1978)|1977/(1977)|1976/(1976)|1975/(1975)|1974/(1974)|1973/(1973)|1972/(1972)|1971/(1971)|1970/(1970)|1969/(1969)|1968/(1968)|1967/(1967)|1966/(1966)|1965/(1965)|1964/(1964)|1963/(1963)|1962/(1962)|1961/(1961)|1960/(1960)|1959/(1959)|1958/(1958)|1957/(1957)|1956/(1956)|1955/(1955)|1954/(1954)|1953/(1953)|1952/(1952)|1951/(1951)|1950/(1950)|1949/(1949)|1948/(1948)|1946/(1946)|1942/(1942)|1939/(1939)|1938/(1938)|1935/(1935)|1927/(1927)
((/(|))/)
-------------------------------------------------------------
Execute these lines on the ROOT directory only to shorten long directory paths.
bluray| bdrip| brrip| 720p| 1080p| 2160p| DTS-HD MA| DTS-HD| TrueHD| DTS-X-HD| DD| x264| h264|-1-0| 1-0|1-0|-2-0| 2-0|2-0|-4-0| 4-0|4-0|-5-1| 5-1|5-1|-6-1| 6-1|6-1|-7-1| 7-1|7-1| atmos| Atm|Directors Cut/DC
-------------------------------------------------------------
So when I pump all these lines into this script, All my files and directories are really left cleaned up. Junk is removed, all years have brackets, and all double stuff is removed. And I will add more stuff to these lines as I see what is left. I have 100,000 files that benefit from this cleaning.
Re: Renaming Folder with RenameItem - Access Denied
For number 02, all failed renames are appended to "unrenameditems" with crlf inbetween each saved name. Then it's all outputed at the end along with the counts of File and folders and the count of successful renames. And all that stuff works. That's how I tell things weren't working right.highend wrote: ↑26 Jan 2025 18:12 01. Begin the script with:
setting "BackgroundFileOps", 0;
02. Thetext ...line at the end does NOT have the string
These items could not be renamed:in it after running it?
03. Show a demo folder structure (with the least amount of files / folders) wich which your script fails so that it can be reproduced
E.g.:Code: Select all
D:\test D:\test\sub1 D:\test\sub1\file1.txt D:\test\sub2 D:\test\sub2\file2.txt
I will add 01, and anything else you think will make this even slicker. I didn't write the whole thing. Somebody else got me started with the mechanics and I been adding features to make it more flexible.
Re: Renaming Folder with RenameItem - Access Denied
Regarding your year replacements, you must be kidding me. Something like this is done via regex (just strip things like 1080 (resolution) before applying it^^)
Code: Select all
$a = "this file is from 1981.txt";
text regexreplace($a, "(\d{4})", "($1)");
One of my scripts helped you out? Please donate via Paypal
Re: Renaming Folder with RenameItem - Access Denied
Yea, I'm a little of everything but not a lot of anything. I made my living with Machine code, C++, and ladder logic. Scripting is no sweat, but I don't know all the syntax. But, yea for like 10 years I been adding "years" to my mask file. I haven't been cleaning for years and now I got a ton of WEB related stuff. So More mask additions I will no doubt be making. I keep most 1080 and other descriptions in the files, but weed them out of the folders. But the WEB folders are 2 and 3 deep with all the same garbage. So Now I added the child folder menu so I can pick which child folders to add to my cleaning.
Yea, I never would have given Regex a second look. I was thinkin those are registry related commands. But, I got a kick out of running all those years. After a slight delay on these fast PCs, my files looked pretty slick. And I got a ton more now to clean up. The internet is so fast now that huge drives fill up quick.
Yea, I never would have given Regex a second look. I was thinkin those are registry related commands. But, I got a kick out of running all those years. After a slight delay on these fast PCs, my files looked pretty slick. And I got a ton more now to clean up. The internet is so fast now that huge drives fill up quick.
Re: Renaming Folder with RenameItem - Access Denied
Ok, it works and does everything that I was expecting it to do. The problem has been some screw up in my windows 7 setup. I booted Win10 mini from an uncorruptible CD and the scripts renamed directories with no sweat. Since it was repeatable as I went back and forth replacing "." with "_" a dozen times, I took the opportunity to clean up the code and fix a few other bugs here and there. I even made the menus clearer so I could understand how to work it a few years from now. I updated the code in this thread, and consider the script finished for my purposes. Now Ill have to figure out why my windows 7 machine is locking directories after running my script. But you know, there were signs of trouble going on even before this. I hot swap drives in and out of my PC and I always "try" to click the eject button in the windows tray. But lots of times it says drive is in use. And I have found nothing that lets me properly eject them. So I pull them out anyway, because no amount of waiting has worked. I could shut the machine off, but I usually have a project I'm working on and closing everything out would be like quitting for the day. Just to swap a drive.
As for renaming drives worth of files, Ill do it with windows on CD. I can't trust so much renaming with my setup in confusion. I have double of all my drives, but it takes over 8 hours to duplicate these drives.
Thanks to all that helped me out. You can try the code yourself and see if it's something that you can use. I loved using it before but now I expect it to help me out even better.
As for renaming drives worth of files, Ill do it with windows on CD. I can't trust so much renaming with my setup in confusion. I have double of all my drives, but it takes over 8 hours to duplicate these drives.
Thanks to all that helped me out. You can try the code yourself and see if it's something that you can use. I loved using it before but now I expect it to help me out even better.
XYplorer Beta Club