Quantcast
Channel: AutoHotkey Community
Viewing all articles
Browse latest Browse all 579

Ask for Help (v1) • FileMove Troubleshooting

$
0
0
I can't get the files to move with this script. It's not adding new lines to the CSV, either.

I hope that it's not too messy. I have a few diagnostic commands in there that I've been using for troubleshooting.

CODE:

#SingleInstance Force
; Set the directory path
dir := "C:\Users\madou\Zotero\storage"

; Check if the directory exists
if !FileExist(dir) {
MsgBox, 16, Error, Directory not found: %dir%
ExitApp
}

; Initialize an empty array to store file names and paths
pdfFiles := {}

; Loop through files in the directory
; Last parameter is Mode.
; If mode is blank or omitted, only files are included and subdirectories are not recursed into. Otherwise, specify one or more of the following letters:
; D = Include directories (folders).
; F = Include files. If both F and D are omitted, files are included but not folders.
; R = Recurse into subdirectories (subfolders). If R is omitted, files and folders in subfolders are not included.
Loop, Files, %dir%\*.pdf, RDF
{
; Get the file name and full path
fileName := A_LoopFileName
filePath := A_LoopFileFullPath

; Add file name and path to the array
pdfFiles[fileName] := filePath
}

; Check if any PDF files were found
if !pdfFiles.Count() {
MsgBox, 16, Error, No PDF files found in: %dir%
ExitApp
}

; Generate timestamp
FormatTime, timestamp,, yyyy-MM-dd-HH-mm

; Create the directory if it doesn't exist
moveTo := "C:\Users\madou\OneDrive - UCLA IT Services\Zotero_moved_delete_after_30_days"
outputDirectory := moveTo . "\file_list"
if (!FileExist(outputDirectory))
FileCreateDir, % outputDirectory

; Create/open the CSV file for writing
outputFile := outputDirectory . "\Zotero_PDF_files.csv"


if (!FileExist(outputFile)) {
colHeaders := "File Name,File Path,Date_Time`n"
FileAppend, % colHeaders, % outputFile
}

FileRead, existingCSV, % outputFile

;~ ; Loop through the array and write each key-value pair to the CSV file
for key, value in pdfFiles {
; Enclose key and value in double quotes
quotedKey := """" key """"
quotedValue := """" value """"

; Create CSV line with quoted key and value
CSV_line := quotedKey "," quotedValue "," """" timestamp """" "`n"

if InStr(existingCSV, CSV_line) {
MsgBox, it ran
FileAppend, % CSV_line , % outputFile
}

FileMove, % quotedValue, % moveTo, 1
}

Statistics: Posted by carsonma — Today, 16:24



Viewing all articles
Browse latest Browse all 579

Trending Articles