服务器共享文件夹可以创建、重命名、允许修改但不能删除共享文件、禁止删除共享文件的方法
这要气好奇葩~
如果只是为了保证这个文件夹存在的话,如果服务器是WINDOWS的话,那么在服务器上编写一个BAT,或者用VB等其他软件写个程序~~~在服务器上定时运行~~~
基本思路,就是在服务器上建立一个计划任务,让它每个多少时间就运行某个文件~~~
然后这个运行的文件,主要是先检测这个文件夹是否存在,若不存在则创建此文件夹~~~
当然,还有一种思路~在你想要的那个文件夹中放一个EXE的可执行文件,然后服务器开机后自动启动这个EXE文件~~~一直别关,那么用户在删除此文件夹的时候,因为文件夹内部的EXE文件是运行中的,所以会提示删除出错,不让删除~~~~~
至于可执行文件的话,我推荐WIN自带的一些小工具,比如计算机 calc.exe~文件下,不占内存,呵呵~~~
word自动保存第一行为文件名的功能在哪里?
此方法是用WORD宏的方法来实现 如果出现用户变量未定义请 在VB编辑器界面选择 工具 引用 找到microsoft scripting runtime , 选中再运行就ok了。News_Content为自定义替换字符。
Option Explicit
Dim arrFiles()
Dim cntFiles%
Sub Main()
Dim i%, StartFolder$, SavePath$
Dim fso As New FileSystemObject, fd As Folder
ReDim arrFiles(1 To 1000)
cntFiles = 0
StartFolder = "D:\Word" '原文件目录
SavePath = "D:\Word2" '改名后的文件目录
Set fd = fso.GetFolder(StartFolder)
SearchFiles fd
ReDim Preserve arrFiles(1 To cntFiles)
For i = 1 To cntFiles
RenameDocument arrFiles(i), SavePath, i
Next i
End Sub
Sub SearchFiles(ByVal fd As Folder)
Dim fl As File
Dim sfd As Folder
For Each fl In fd.Files
If LCase(Right(fl.Path, 4)) = ".doc" Then
cntFiles = cntFiles + 1
If cntFiles >= UBound(arrFiles) Then ReDim Preserve arrFiles(1 To cntFiles + 1000)
arrFiles(cntFiles) = fl.Path
End If
Next fl
If fd.SubFolders.Count = 0 Then Exit Sub
For Each sfd In fd.SubFolders
SearchFiles sfd
Next
End Sub
Sub RenameDocument(ByVal wordFileName, ByVal wordFilePath, ByVal num)
On Error Resume Next
Dim myTitle$, myFileName$
Dim mydoc As Document, myRange As Range
Dim News_Content
Set mydoc = Word.Documents.Add
mydoc.Activate
Selection.InsertFile FileName:=wordFileName, Range:="", ConfirmConversions:= _
False, Link:=False, Attachment:=False
ActiveWindow.View.Type = wdPageView
Set myRange = mydoc.Paragraphs.First.Range
myRange.SetRange myRange.Start, myRange.End - 1
News_Content = Trim(myRange.Text)
News_Content = Replace(News_Content, "!", "_")
News_Content = Replace(News_Content, "/", "")
News_Content = Replace(News_Content, "。", "")
News_Content = Replace(News_Content, " ", "")
News_Content = Replace(News_Content, "(", "")
News_Content = Replace(News_Content, ")", "")
News_Content = Replace(News_Content, "“", "")
News_Content = Replace(News_Content, "”", "")
News_Content = Replace(News_Content, " ", "")
myTitle = News_Content
If (myTitle = "") Or (Len(myTitle) > 50) Then
Debug.Print "ERR:--------------------------------------------" + wordFileName
Shell "cmd.exe /c echo " & "ERR:--------------------------------------------" & wordFileName & ">>D:\Word.log"
mydoc.Close SaveChanges:=wdDoNotSaveChanges
SendKeys ("{ESC}")
Exit Sub
End If
myFileName = wordFilePath + "\" + myTitle + ".doc"
mydoc.SaveAs myFileName
mydoc.Close SaveChanges:=wdDoNotSaveChanges
Debug.Print num & ":" & wordFileName & "=" & myFileName
Shell "cmd.exe /c echo " & num & ":" & wordFileName & "=" & myFileName & ">>D:\Word.log"
End Sub
python小白 求助 读取txt文件,并进行数据处理
让写代码给5分,太没诚意了,哈哈,不过还是给你吧,没有测试过,你试试再说吧,执行的时候把最后一行的参数设置成你文件的存放位置就可以了def file_pro(file_dir): import os """ 输入一个文件夹,文件夹下是所有待处理文件 :param file_dir: 待处理的文件所在的文件夹 :return: null """ # 获取文件列表 file_list = os.listdir(file_dir) # 建立结果文件,与程序在同级目录 result_file = open('result.csv', 'a+', encoding='GBK') for file in file_list: file_to_pro = file_dir + os.sep + file result = [] for num, line in enumerate(open(file_to_pro)): if num >= 32: if line.split(' ')[2] == '3CD': result.clear() result += line.split(' ')[6:] last_result = file_to_pro + ',3CD,' for item in result: last_result += (str(int(item, 16)) + ',') result_file.writelines(last_result)file_pro("c:\\")
python 文本文件处理
分隔日志文件存为小文件#coding:utf-8 #file: FileSplit.pyimport os,os.path,timedef FileSplit(sourceFile, targetFolder):sFile = open(sourceFile, 'r')number = 100000#每个小文件中保存100000条数据dataLine = sFile.readline()tempData = []#缓存列表fileNum = 1if not os.path.isdir(targetFolder): #如果目标目录不存在,则创建os.mkdir(targetFolder)while dataLine:#有数据for row in range(number): tempData.append(dataLine)#将一行数据添加到列表中dataLine = sFile.readline()if not dataLine :breaktFilename = os.path.join(targetFolder,os.path.split(sourceFile)[1] + str(fileNum) + ".txt")tFile = open(tFilename, 'a+')#创建小文件tFile.writelines(tempData)#将列表保存到文件中tFile.close() tempData = []#清空缓存列表print(tFilename + " 创建于: " + str(time.ctime()))fileNum += 1#文件编号sFile.close()if __name__ == "__main__" :FileSplit("access.log","access")分类汇总小文件:#coding:utf-8 #file: Map.pyimport os,os.path,redef Map(sourceFile, targetFolder):sFile = open(sourceFile, 'r')dataLine = sFile.readline()tempData = {}#缓存列表if not os.path.isdir(targetFolder): #如果目标目录不存在,则创建os.mkdir(targetFolder)while dataLine:#有数据p_re = re.compile(r'(GET|POST)\s(.*?)\sHTTP/1.[01]',re.IGNORECASE) #用正则表达式解析数据match = p_re.findall(dataLine)if match:visitUrl = match[0][1]if visitUrl in tempData:tempData[visitUrl] += 1else:tempData[visitUrl] = 1dataLine = sFile.readline()#读入下一行数据sFile.close()tList = []for key,value in sorted(tempData.items(),key = lambda k:k[1],reverse = True):tList.append(key + " " + str(value) + '\n')tFilename = os.path.join(targetFolder,os.path.split(sourceFile)[1] + "_map.txt")tFile = open(tFilename, 'a+')#创建小文件tFile.writelines(tList)#将列表保存到文件中tFile.close()if __name__ == "__main__" :Map("access\\access.log1.txt","access")Map("access\\access.log2.txt","access")Map("access\\access.log3.txt","access")3. 再次将多个文件分类汇总为一个文件。#coding:utf-8 #file: Reduce.pyimport os,os.path,redef Reduce(sourceFolder, targetFile):tempData = {}#缓存列表p_re = re.compile(r'(.*?)(\d{1,}$)',re.IGNORECASE) #用正则表达式解析数据for root,dirs,files in os.walk(sourceFolder):for fil in files:if fil.endswith('_map.txt'):#是reduce文件sFile = open(os.path.abspath(os.path.join(root,fil)), 'r')dataLine = sFile.readline()while dataLine:#有数据subdata = p_re.findall(dataLine) #用空格分割数据#print(subdata[0][0]," ",subdata[0][1])if subdata[0][0] in tempData:tempData[subdata[0][0]] += int(subdata[0][1])else:tempData[subdata[0][0]] = int(subdata[0][1])dataLine = sFile.readline()#读入下一行数据sFile.close()tList = []for key,value in sorted(tempData.items(),key = lambda k:k[1],reverse = True):tList.append(key + " " + str(value) + '\n')tFilename = os.path.join(sourceFolder,targetFile + "_reduce.txt")tFile = open(tFilename, 'a+')#创建小文件tFile.writelines(tList)#将列表保存到文件中tFile.close()if __name__ == "__main__" :Reduce("access","access")