Sign in to follow this  
Followers 0
yaredou

Help creating a folder with hyphens (dashes)

4 posts in this topic

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

Share this post


Link to post
Share on other sites



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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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!

Share this post


Link to post
Share on other sites

yaredou,

We try to please! ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0