Jump to content

Help creating a folder with hyphens (dashes)


Recommended Posts

Hello folks,

I'm writing a script to go through a list of files, check the date, if older than a week, move them to a folder named with the file date as YYYY-MM-DD. It is necessary for the folder name to contained hyphens to follow convention. I'm running into a problem with the DirCreate function however in that it will not create the folder if the name contains hyphens.

Below is the part of my code that deals with the files. Any ideas?

Thanks much,

; set working directory for moving files
$dir_m = "\\10.10.20.21\c$\Daily"
FileChangeDir($dir_m)
dim $dirpath

;Find Old version of files
$FileList=_FileListToArray($dir_m)
If @Error=1 Then
MsgBox (0,"","No Files\Folders Found.")
Exit
EndIf
_ArrayDisplay($FileList,"$FileList")

;For/Next loop to step through the array:

For $n = 1 To $FileList[0] ; [0] = line count
    $fileinfo = FileGetTime ($FileList[$n])
    ;MsgBox (0, "Filedate", $fileinfo[0] & "/" & $fileinfo[1] & "/" & $fileinfo[2] )
    $Filedate = $fileinfo[0] & "/" & $fileinfo[1] & "/" & $fileinfo[2]
    $FileAge = _DateDiff ('w', $Filedate, _NowCalc())       ; Determine if file is older than 1 week old - 'w' flag indicates week

    If $FileAge >= 1 Then                                   ; If older than one week move to the appropriate folder  - create if doesn't exist
        $hyp = "-"
        $dirpath = $fileinfo[0] & "-" & $fileinfo[1] & "-" & $fileinfo[2]       ;msgbox (0, "move this file", $FileList[$n])
        ;DirCreate ($dir_m & "\" & $dirpath)
        ;DirCreate ($dir_m & "\" & "test-1")
        ;DirCreate ($dir_m & "\" & $fileinfo[0] & $hyp & $fileinfo[1] & $hyp & $fileinfo[2])
        ;FileMove ($FileList[$n], $dir_m & "\" & $dirpath, 8)

    EndIf


;MsgBox(64, "Current file:", $FileList[$n])
Next
Link to comment
Share on other sites

  • Moderators

yaredou,

DirCreate creates folders with hyphenated names without problem - I have just run your code and it created hyphenated folders in the base folder for all files older than a week. :)

Do you have the necessary permissions to create the folders? ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23, right again. The permissions were ok, what happened is that a previous faulty execution of the program created extension-less files that the code mistook for folders. After deleting these files, the folders were created without a problem. I appreciate your prompt response!

Link to comment
Share on other sites

  • Moderators

yaredou,

We try to please! ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...