I think it has something to do with AutohotKey. It created the folders in the first place, but now it can't delete them. But if I personally create a folder, I can manipulate its read-only tag all I want using AutohotKey.
Also, yes, as Administrator I do have all privelages to make modifications... so eh?
As for a gosub, it makes no difference -- I've tried using entirely different scripts to accomplish this and they won't do it.
Here, try this. Use AutoHotkey to copy a CD over to your hard drive somewhere and make it first run a loop through to create all the directories, then shuffle all the files in. (I had to do this because I made a progress bar, and I needed a log of all the moved files). Then try to turn read-only off using your script, or even another. Now over here, using XP SP2, that doesn't fly. I don't know why.
Maybe you can save yourself a little time by taking portions of my code... who knows. I just want someone to be able to reproduce the error. Hell, I could post the entire program I'm working on if it'll help...
Code:
2ButtonCopy: // If the user clicks Copy...
{
Gui, 2: Submit, NoHide // Gather all the variables and hide the window...
If(!destination) // If the user did not enter a destination...
{
MsgBox, 48, No Destination, Please enter a destination directory. // Display error message.
ControlFocus, Edit1, Copy from Disc // Change focus to the field in question.
Return // Wait for user input.
}
Else If destination Contains *,",?,/,\,|,<,> // If the destination contains *, ", ?, /, \, |, <, or >...
{
MsgBox, 48, Invalid Destination, The destination must not contain question marks, quotation marks, colons,`nslashes, backslashes, pipes, greater-than or less-than signs, or asterisks.
ControlFocus, Edit1, Copy from Disc // Change focus to the field in question.
Send, {END}{SHIFTDOWN}{HOME}{SHIFTUP} // Highlight the contents.
Return // Wait for user input.
}
Gui, 2: Destroy // Destroy the copy settings window.
StringMid, disc_drive, disc_drives_choose, 1, 1 // Grab the drive letter.
Gui, 3: Add, Progress, x10 y30 w300 h15 vcopy_progress // Draw the progress bar "copy_progress".
Gui, 3: Add, Text, x10 y48 w300 vmb_status // Draw the current MB text display.
Gui, 3: Add, Text, x10 y63 w300 vcurrent_file // Draw the current file text display.
Gui, 3: Add, Text, x10 y78 w75 Left, Project: %project% // Draw the project.
Gui, 3: Add, Text, x85 y78 w225 Right, Destination: %project%\%destination% // Draw the destination.
Gui, 3: Add, Button, x128 y96 w63 h30 vbutton, Cancel // Cancel button.
Gui, 3: Font, s13 Bold
Gui, 3: Add, Text, x10 y5 w300 Center vpercent_display // Draw the current MB text display.
Gui, 3: Show, , Copy from Disc // Make the window.
already_present = 0
IfExist, %Dayend_Directory%\%project%\%destination%
already_present = 1
FileCreateDir, %Dayend_Directory%\%project%\%destination% // Create the directory.
SetBatchLines, -1 // Make the operation run at maximum speed.
total_size = // Initialize variable "total_size" for progress bar.
current_size = // Initialize variable "current_size" for progress bar.
good_to_go = 1 // Initialize variable "good_to_go" and set it to 1.
directories_copied =
files_copied =
done_copying =
Loop, %disc_drive%:\*.*, 1, 1 // Parse through the entire disc.
total_size += %A_LoopFileSize% // Add up all the bytes for a total size.
SetFormat, Float, 0.2 // Set format of numeric strings to two decimal places.
total_mb := total_size / 1048576 // Calculate total MB to be transferred.
Loop, %disc_drive%:\*.*, 2, 1 // Parse through all directories and subdirectories (no files).
{
StringTrimLeft, dir_struct, A_LoopFileFullPath, 3 // Remove the drive letter, colon, and backslash.
directories_copied = %directories_copied%`n%A_LoopFileFullPath%
FileCreateDir, %Dayend_Directory%\%project%\%destination%\%dir_struct% // Create this directory and all its parents, if necessary.
GuiControl, 3: , current_file, %A_LoopFileFullPath% // Update the current file text display.
GuiControl, 3: , mb_status, Creating directory structure... // Update the current MB text display.
}
Loop, %disc_drive%:\*.*, 0, 1 // Parse through all files and files in subdirectories (no folders).
{
SetFormat, Float, 0.2 // Set format of numeric strings to two decimal places.
If(good_to_go = 0) // If variable "good_to_go" has been changed to 0 by a cancellation...
Break // Break the loop.
current_size += %A_LoopFileSize% // Add this file's size to the current size.
percent_complete := current_size / total_size * 100 // Create a percentage complete to use in the progress bar.
current_mb := current_size / 1048576 // Calculate current MB transferred.
StringTrimLeft, dir_struct, A_LoopFileDir, 3 // Remove the drive letter, colon, and backslash.
files_copied = %files_copied%`n%A_LoopFileFullPath%
FileCopy, %A_LoopFileFullPath%, %Dayend_Directory%\%project%\%destination%\%dir_struct%\%A_LoopFileName%, 1
GuiControl, 3: , copy_progress, %percent_complete% // Update the progress bar.
GuiControl, 3: , mb_status, %current_mb% MB of %total_mb% MB Transferred // Update the current MB text display.
GuiControl, 3: , current_file, %A_LoopFileFullPath% // Update the current file text display.
GuiControl, 3: , percent_display, %percent_complete%`% // Display percentage on title bar.
}
GuiControl, 3: , button, Done // Change the Cancel button to a Done button.
done_copying = 1
Return // Wait for user input.
3GuiEscape: // If user presses Escape...
3ButtonCancel: // If user clicks Cancel...
3GuiClose: // If user exits some other way...
{
If(!done_copying)
{
MsgBox, 33, Stop Copy, Are you sure you want to stop the transfer?
IfMsgBox, OK
{
good_to_go = 0 // Cancel the copy loop by setting "good_to_go" to 0.
MsgBox, 33, Delete Files, Do you want to delete the files that were copied over?
IfMsgBox, OK
{
Gui, 3: Show, , Delete Files // Make the window.
GuiControl, 3: Disable, button
good_to_go = 0 // Cancel the copy loop by setting "good_to_go" to 0.
total_size = %current_size% // Initialize variable "total_size" for progress bar.
current_size = // Initialize variable "current_size" for progress bar.
SetFormat, Float, 0.2 // Set format of numeric strings to two decimal places.
total_mb := total_size / 1048576 // Calculate total MB to be deleted.
StringReplace, files_copied_fixed, files_copied, %disc_drive%:\, %Dayend_Directory%\%project%\%destination%\, All
StringReplace, directories_copied_fixed, directories_copied, %disc_drive%:\, %Dayend_Directory%\%project%\%destination%\, All
Sort, directories_copied_fixed, R // WON'T NEED THIS IF HE FIXES IT
FileSetAttrib, -R, %Dayend_Directory%\%project%\%destination%\*.*, 1, 1
Loop, Parse, files_copied_fixed, `n // Parse through all directories and subdirectories (no files).
{
if A_LoopField = // Omit the last `n so we don't get a double entry.
Continue
FileGetSize, current_size_file, %A_LoopField%
current_size += %current_size_file% // Subtract this file's size from the current size.
percent_complete := current_size / total_size * 100 // Create a percentage complete to use in the progress bar.
current_mb := current_size / 1048576 // Calculate current MB deleted.
FileSetAttrib, -R, %A_LoopField%, 1 // WON'T NEED THIS IF HE FIXES IT
FileDelete, %A_LoopField%
GuiControl, 3: , copy_progress, %percent_complete% // Update the progress bar.
GuiControl, 3: , mb_status, %current_mb% MB of %total_mb% MB Deleted // Update the current MB text display.
GuiControl, 3: , current_file, %A_LoopField% // Update the current file text display.
GuiControl, 3: , percent_display, %percent_complete%`% // Display percentage on title bar.
}
Loop, Parse, directories_copied_fixed, `n // Parse through all directories and subdirectories (no files).
{
if A_LoopField = // Omit the last `n so we don't get a double entry.
Continue
FileDelete, %A_LoopField%
GuiControl, 3: , current_file, %A_LoopField% // Update the current file text display.
GuiControl, 3: , mb_status, Removing directory structure... // Update the current MB text display.
}
GuiControl, 3: , copy_progress, 100 // Update the progress bar.
GuiControl, 3: , percent_display, 100`% // Display percentage on title bar.
GuiControl, 3: Enable, button
GuiControl, 3: , button, Done // Change the Cancel button to a Done button.
If(!already_present)
{
FileDelete, %Dayend_Directory%\%project%\%destination%
GuiControl, 3: , current_file, %Dayend_Directory%\%project%\%destination% // Update the current file text display.
}
Return // Wait for user input.
}
Else IfMsgBox, Cancel
{
Gui, 3: Destroy // Destroy the window.
Return // Wait for user input.
}
}
Else IfMsgBox, Cancel
{
Return // Wait for user input.
}
}
Else
{
Gui, 3: Destroy // Destroy the window.
Return // Wait for user input.
}
}
}