導航:首頁 > 文件處理 > 編程代碼的合集文件夾

編程代碼的合集文件夾

發布時間:2022-11-25 13:48:35

① 如何用c++編程創建一系列文件夾給出源代碼

c++本身不能創建文件夾,可以調用系統函數system("md 文件夾名")
#include <iostream>
#include <string>
using namespace std;
int main()
{
cout <<"輸入要創建文件夾的位置和名字:"<<endl;
cout <<"例如: c:\\contacts"<<endl;
string path;
cin >>path;
path="md "+path;
system(path.c_str());
}
http://..com/question/66513906.html?fr=ala3

② 常用代碼合集

1、禁止手機睡眠

[UIApplication sharedApplication].idleTimerDisabled = YES;

2、隱藏某行cell

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

// 如果是你需要隱藏的那一行,返回高度為0

    if(indexPath.row == YouWantToHideRow){

        return 0;

    }  return 44;

}

// 然後再你需要隱藏cell的時候調用

[self.tableView beginUpdates];

[self.tableView endUpdates];

3、禁用button高亮

button.adjustsImageWhenHighlighted = NO;

4、tableview遇到這種報錯failed to obtain a cell from its dataSource

是因為你的cell被調用的早了。先循環使用了cell,後又創建cell。順序錯了

可能原因:1、xib的cell沒有注冊 2、內存中已經有這個cell的緩存了(也就是說通過你的cellId找到的cell並不是你想要的類型),這時候需要改下cell的標識

5、去除數組中重復的對象

NSArray *newArr = [oldArr valueForKeyPath:@「@distinctUnionOfObjects.self"];

6、動態修改ableView的tableHeaderView或者tableFooterView的高度

開發中如果要動態修改tableView的tableHeaderView或者tableFooterView的高度,需要給tableView重新設置,而不是直接更改高度。正確的做法是重新設置一下tableView.tableFooterView = 更改過高度的view。為什麼?其實在iOS8以上直接改高度是沒有問題的,在iOS8中出現了contentSize不準確的問題,這是解決辦法。

7、collectionView的內容小於其寬高的時候是不能滾動的,設置可以滾動:

collectionView.alwaysBounceHorizontal = YES;

collectionView.alwaysBounceVertical = YES;

8、顏色轉圖片

+ (UIImage *)cl_imageWithColor:(UIColor *)color {

  CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);

  UIGraphicsBeginImageContext(rect.size);

  CGContextRef context = UIGraphicsGetCurrentContext();

  (context, [color CGColor]);

  CGContextFillRect(context, rect);

  UIImage *image = ();

  UIGraphicsEndImageContext();

  return image;

}

9、view設置圓角

#define ViewBorderRadius(View, Radius, Width, Color)

[View.layer setCornerRadius:(Radius)];\

[View.layer setMasksToBounds:YES];\

[View.layer setBorderWidth:(Width)];\

[View.layer setBorderColor:[Color CGColor]] // view圓角

10、強/弱引用

#define WeakSelf(type)  __weak typeof(type) weak##type = type; // weak

#define StrongSelf(type)  __strong typeof(type) type = weak##type; // strong

11、由角度轉換弧度

#define DegreesToRadian(x) (M_PI * (x) / 180.0)

12、由弧度轉換角度

#define RadianToDegrees(radian) (radian*180.0)/(M_PI)

13、獲取app緩存大小

- (CGFloat)getCachSize {

    NSUInteger imageCacheSize = [[SDImageCache sharedImageCache] getSize];

    //獲取自定義緩存大小

    //用枚舉器遍歷 一個文件夾的內容

    //1.獲取 文件夾枚舉器

    NSString *myCachePath = [NSHomeDirectory() :@"Library/Caches"];

    NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager] enumeratorAtPath:myCachePath];

    __block NSUInteger count = 0;

    //2.遍歷

    for (NSString *fileName in enumerator) {

        NSString *path = [myCachePath :fileName];

        NSDictionary *fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath:path error:nil];

        count += fileDict.fileSize;//自定義所有緩存大小

    }

    // 得到是位元組  轉化為M

    CGFloat totalSize = ((CGFloat)imageCacheSize+count)/1024/1024;

    return totalSize;

}

14、清理app緩存

- (void)handleClearView {

    //刪除兩部分

    //1.刪除 sd 圖片緩存

    //先清除內存中的圖片緩存

    [[SDImageCache sharedImageCache] clearMemory];

    //清除磁碟的緩存

    [[SDImageCache sharedImageCache] clearDisk];

    //2.刪除自己緩存

    NSString *myCachePath = [NSHomeDirectory() :@"Library/Caches"];

    [[NSFileManager defaultManager] removeItemAtPath:myCachePath error:nil];

}

15、幾個常用許可權判斷

    if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {

        NSLog(@"沒有定位許可權");

    }

    AVAuthorizationStatus statusVideo = [AVCaptureDevice :AVMediaTypeVideo];

    if (statusVideo == AVAuthorizationStatusDenied) {

        NSLog(@"沒有攝像頭許可權");

    }

    //是否有麥克風許可權

    AVAuthorizationStatus statusAudio = [AVCaptureDevice :AVMediaTypeAudio];

    if (statusAudio == AVAuthorizationStatusDenied) {

        NSLog(@"沒有錄音許可權");

    }

    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {

        if (status == PHAuthorizationStatusDenied) {

            NSLog(@"沒有相冊許可權");

        }

    }];

16、長按復制功能

- (void)viewDidLoad

{

    [self.view addGestureRecognizer:[[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(pasteBoard:)]];

}

- (void)pasteBoard:(UILongPressGestureRecognizer *)longPress {

    if (longPress.state == UIGestureRecognizerStateBegan) {

        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];

        pasteboard.string = @"需要復制的文本";

    }

}

17、image拉伸

+ (UIImage *)resizableImage:(NSString *)imageName

{

    UIImage *image = [UIImage imageNamed:imageName];

    CGFloat imageW = image.size.width;

    CGFloat imageH = image.size.height;

    return [image resizableImageWithCapInsets:UIEdgeInsetsMake(imageH * 0.5, imageW * 0.5, imageH * 0.5, imageW * 0.5) resizingMode:UIImageResizingModeStretch];

}

18、JSON字元串轉字典

+ (NSDictionary *)parseJSONStringToNSDictionary:(NSString *)JSONString {

    NSData *JSONData = [JSONString dataUsingEncoding:NSUTF8StringEncoding];

    NSDictionary *responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingMutableLeaves error:nil];

    return responseJSON;

}

19、畫水印

// 畫水印

- (void) setImage:(UIImage *)image withWaterMark:(UIImage *)mark inRect:(CGRect)rect

{

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.0)

    {

        (self.frame.size, NO, 0.0);

    }

    //原圖

    [image drawInRect:self.bounds];

    //水印圖

    [mark drawInRect:rect];

    UIImage *newPic = ();

    UIGraphicsEndImageContext();

    self.image = newPic;

}

20、身份證號驗證

- (BOOL)validateIdentityCard {

    BOOL flag;

    if (self.length <= 0) {

        flag = NO;

        return flag;

    }

    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";

    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];

    return [identityCardPredicate evaluateWithObject:self];

}

21、移除字元串中的空格和換行

+ (NSString *)removeSpaceAndNewline:(NSString *)str {

    NSString *temp = [str :@" " withString:@""];

    temp = [temp :@"\r" withString:@""];

    temp = [temp :@"\n" withString:@""];

    return temp;

}

22、判斷字元串中是否有空格

+ (BOOL)isBlank:(NSString *)str {

    NSRange _range = [str rangeOfString:@" "];

    if (_range.location != NSNotFound) {

        //有空格

        return YES;

    } else {

        //沒有空格

        return NO;

    }

}

22、獲取一個視頻的第一幀圖片

    NSURL *url = [NSURL URLWithString:filepath];

    AVURLAsset *asset1 = [[AVURLAsset alloc] initWithURL:url options:nil];

    AVAssetImageGenerator *generate1 = [[AVAssetImageGenerator alloc] initWithAsset:asset1];

    generate1. = YES;

    NSError *err = NULL;

    CMTime time = CMTimeMake(1, 2);

    CGImageRef oneRef = [generate1 CGImageAtTime:time actualTime:NULL error:&err];

    UIImage *one = [[UIImage alloc] initWithCGImage:oneRef];

    return one;

23、獲取視頻的時長

+ (NSInteger)getVideoTimeByUrlString:(NSString *)urlString {

    NSURL *videoUrl = [NSURL URLWithString:urlString];

    AVURLAsset *avUrl = [AVURLAsset assetWithURL:videoUrl];

    CMTime time = [avUrl ration];

    int seconds = ceil(time.value/time.timescale);

    return seconds;

}

24、UILabel設置內邊距

子類化UILabel,重寫drawTextInRect方法

- (void)drawTextInRect:(CGRect)rect {

    // 邊距,上左下右

    UIEdgeInsets insets = {0, 5, 0, 5};

    [super drawTextInRect:UIEdgeInsetsInsetRect(rect, insets)];

}

25、UILabel設置文字描邊

子類化UILabel,重寫drawTextInRect方法

- (void)drawTextInRect:(CGRect)rect

{

    CGContextRef c = UIGraphicsGetCurrentContext();

    // 設置描邊寬度

    CGContextSetLineWidth(c, 1);

    CGContextSetLineJoin(c, kCGLineJoinRound);

    CGContextSetTextDrawingMode(c, kCGTextStroke);

    // 描邊顏色

    self.textColor = [UIColor redColor];

    [super drawTextInRect:rect];

    // 文本顏色

    self.textColor = [UIColor yellowColor];

    CGContextSetTextDrawingMode(c, kCGTextFill);

    [super drawTextInRect:rect];

}

26、在狀態欄增加網路請求的菊花,類似safari載入網頁的時候狀態欄菊花

[UIApplication sharedApplication]. = YES;

27、修改cell.imageView的大小

UIImage *icon = [UIImage imageNamed:@""];

CGSize itemSize = CGSizeMake(30, 30);

(itemSize, NO ,0.0);

CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);

[icon drawInRect:imageRect];

cell.imageView.image = ();

UIGraphicsEndImageContext();

28、為一個view添加虛線邊框

CAShapeLayer *border = [CAShapeLayer layer];

    border.strokeColor = [UIColor colorWithRed:67/255.0f green:37/255.0f blue:83/255.0f alpha:1].CGColor;

    border.fillColor = nil;

    border.lineDashPattern = @[@4, @2];

    border.path = [UIBezierPath bezierPathWithRect:view.bounds].CGPath;

    border.frame = view.bounds;

    [view.layer addSublayer:border];

29、UITextView中打開或禁用復制,剪切,選擇,全選等功能

// 繼承UITextView重寫這個方法

- (BOOL)canPerformAction:(SEL)action withSender:(id)sender

{

// 返回NO為禁用,YES為開啟

    // 粘貼

    if (action == @selector(paste:)) return NO;

    // 剪切

    if (action == @selector(cut:)) return NO;

    // 復制

    if (action == @selector(:)) return NO;

    // 選擇

    if (action == @selector(select:)) return NO;

    // 選中全部

    if (action == @selector(selectAll:)) return NO;

    // 刪除

    if (action == @selector(delete:)) return NO;

    // 分享

    if (action == @selector(share)) return NO;

    return [super canPerformAction:action withSender:sender];

}

30、tableViewCell分割線頂到頭

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    [cell setSeparatorInset:UIEdgeInsetsZero];

    [cell setLayoutMargins:UIEdgeInsetsZero];

    cell. = NO;

}

- (void)viewDidLayoutSubviews {

    [self.tableView setSeparatorInset:UIEdgeInsetsZero];

    [self.tableView setLayoutMargins:UIEdgeInsetsZero];

}

③ 在vs2010中編譯好的代碼默認的存儲位置在c盤的那個文件夾

存在項目文件夾里,你新建項目時不是有個存儲路徑嗎。
不知道的話,在vs里打開項目,右擊項目名稱---在windows資源管理器中打開文件夾。

④ 如何用java代碼創建一個文件夾

File dir=new File("文件夾");
if(!dir.exists()) dir.mkdir();

⑤ vs編程例子代碼在哪個文件夾下

我的是在「我的文檔」下的「Visual Studio 2010」這個文件夾。
一般都會保存在D盤下,可以找一找。

⑥ 一個C++項目中、幾個文件夾中哪些代碼是自己寫的

一般都是頭文件和源文件這兩個文件夾裡面有自己寫的代碼,生成的文件和資源文件這兩個文件夾是放項目編譯之後生成的文件和項目運行時需要的一些jar包等資源的。這兩個文件夾都是系統自動生成的,不用去管它。謝謝樓主!

⑦ 源代碼哪個文件夾里是視頻

源代碼哪個文件夾里是視頻,就是把它的ASCII碼保存到硬碟上了,打開該文件的時候,記事本又會把這些碼翻譯成一個一個字元顯示在你在面前,這種關系是存在操作系統內部的,編程人員只知道它存在就行了。

知識擴展:

源代碼(也稱源程序)是指未編譯的按照一定的程序設計語言規范書寫的文本文件,是一系列人類可讀的計算機語言指令。 在現代程序語言中,源代碼可以是以書籍或者磁帶的形式出現,但最為常用的格式是文本文件,這種典型格式的目的是為了編譯出計算機程序。計算機源代碼的最終目的是將人類可讀的文本翻譯成為計算機可以執行的二進制指令,這種過程叫作編譯,通過編譯器完成。

源程序一般就是可以用記事本打開的好多行英文的,用編程語言寫好的軟體。源程序經過編譯成目標程序,才能運行。一般目標程序不能再修改了。我們電腦上安裝的軟體都是目標程序。除了腳本語言的源程序外,其他源程序是不能直接運行的。



⑧ 好玩的文件夾代碼

在你電腦上新建個文本文檔然後輸color+c,tree+d,然後保存並把文件後綴txt改成bat。
彈出窗口,康完才能關的。
新建文本文檔>編輯>如下:msgbox「今天是植樹節吖,」msgbox「人家說要栽在喜歡的人手裡,」msgbox「那我要栽在你的手裡吖」,msgbox「驚不驚喜吖」,msgbox「別急!往下康吖」,msgbox「因為你很土吖哈哈哈」,msgbox「哈哈哈哈笨蛋」等。
左上角文件點擊保存->關掉->重命名->修改文件類型為vbs->雙擊點開->效果。

⑨ 如何用JAVA代碼創建一個文件夾

File類裡面有兩個方法可以實現:x0dx0a一個是mkdir():創建此抽象路徑名指定的目錄。x0dx0a另外一個是mkdirs(): 創建此抽象路徑名指定的目錄,包括所有必需但不存在的父目錄。x0dx0ax0dx0a比如你想在A文件夾創建一個B文件夾,並在B文件夾下創建c和D文件夾,可以用下面的代碼實現:x0dx0ax0dx0aimport java.io.File;x0dx0ax0dx0apublic class Test {x0dx0a public static void main(String args[]) {x0dx0a File file = new File("D:\\A\\B\\C");x0dx0a file.mkdirs();x0dx0a x0dx0a file = new File("D:\\A\\B\\D");x0dx0a file.mkdir();x0dx0a }x0dx0a}

⑩ 怎麼用C語言編程遍歷文件夾下所有文件名


/**************************************************
這是CBrowseDir的類定義文件BrowseDir.h

/**************************************************
#include"stdlib.h"

classCBrowseDir
{
protected:
//存放初始目錄的絕對路徑,以''結尾
charm_szInitDir[_MAX_PATH];

public:
//預設構造器
CBrowseDir();

//設置初始目錄為dir,如果返回false,表示目錄不可用
boolSetInitDir(constchar*dir);

//開始遍歷初始目錄及其子目錄下由filespec指定類型的文件
//filespec可以使用通配符*?,不能包含路徑。
//如果返回false,表示遍歷過程被用戶中止
boolBeginBrowse(constchar*filespec);

protected:
//遍歷目錄dir下由filespec指定的文件
//對於子目錄,採用迭代的方法
//如果返回false,表示中止遍歷文件
boolBrowseDir(constchar*dir,constchar*filespec);

//函數BrowseDir每找到一個文件,就調用ProcessFile
//並把文件名作為參數傳遞過去
//如果返回false,表示中止遍歷文件
//用戶可以覆寫該函數,加入自己的處理代碼
virtualboolProcessFile(constchar*filename);

//函數BrowseDir每進入一個目錄,就調用ProcessDir
//並把正在處理的目錄名及上一級目錄名作為參數傳遞過去
//如果正在處理的是初始目錄,則parentdir=NULL
//用戶可以覆寫該函數,加入自己的處理代碼
//比如用戶可以在這里統計子目錄的個數
virtualvoidProcessDir(constchar
*currentdir,constchar*parentdir);
};


/*********************************************/

這是CBrowseDir的類實現文件BrowseDir.cpp

/***********************************************/
#include"stdlib.h"
#include"direct.h"
#include"string.h"
#include"io.h"

#include"browsedir.h"

CBrowseDir::CBrowseDir()
{
//用當前目錄初始化m_szInitDir
getcwd(m_szInitDir,_MAX_PATH);

//如果目錄的最後一個字母不是'',則在最後加上一個''
intlen=strlen(m_szInitDir);
if(m_szInitDir[len-1]!='\')
strcat(m_szInitDir,"\");
}

boolCBrowseDir::SetInitDir(constchar*dir)
{
//先把dir轉換為絕對路徑
if(_fullpath(m_szInitDir,dir,_MAX_PATH)==NULL)
returnfalse;

//判斷目錄是否存在
if(_chdir(m_szInitDir)!=0)
returnfalse;

//如果目錄的最後一個字母不是'',則在最後加上一個''
intlen=strlen(m_szInitDir);
if(m_szInitDir[len-1]!='\')
strcat(m_szInitDir,"\");

returntrue;
}

boolCBrowseDir::BeginBrowse(constchar*filespec)
{
ProcessDir(m_szInitDir,NULL);
returnBrowseDir(m_szInitDir,filespec);
}

boolCBrowseDir::BrowseDir
(constchar*dir,constchar*filespec)
{
_chdir(dir);

//首先查找dir中符合要求的文件
longhFile;
_finddata_tfileinfo;
if((hFile=_findfirst(filespec,&fileinfo))!=-1)
{
do
{
//檢查是不是目錄
//如果不是,則進行處理
if(!(fileinfo.attrib&_A_SUBDIR))
{
charfilename[_MAX_PATH];
strcpy(filename,dir);
strcat(filename,fileinfo.name);
if(!ProcessFile(filename))
returnfalse;
}
}while(_findnext(hFile,&fileinfo)==0);
_findclose(hFile);
}

//查找dir中的子目錄
//因為在處理dir中的文件時,派生類的ProcessFile有可能改變了
//當前目錄,因此還要重新設置當前目錄為dir。
//執行過_findfirst後,可能系統記錄下了相關信息,因此改變目錄
//對_findnext沒有影響。
_chdir(dir);
if((hFile=_findfirst("*.*",&fileinfo))!=-1)
{
do
{
//檢查是不是目錄
//如果是,再檢查是不是.或..
//如果不是,進行迭代
if((fileinfo.attrib&_A_SUBDIR))
{
if(strcmp(fileinfo.name,".")!=0&&strcmp
(fileinfo.name,"..")!=0)
{
charsubdir[_MAX_PATH];
strcpy(subdir,dir);
strcat(subdir,fileinfo.name);
strcat(subdir,"\");
ProcessDir(subdir,dir);
if(!BrowseDir(subdir,filespec))
returnfalse;
}
}
}while(_findnext(hFile,&fileinfo)==0);
_findclose(hFile);
}
returntrue;
}

boolCBrowseDir::ProcessFile(constchar*filename)
{
returntrue;
}

voidCBrowseDir::ProcessDir(constchar
*currentdir,constchar*parentdir)
{
}


/*************************************************
這是例子example.cpp

/*************************************************
#include"stdio.h"

#include"BrowseDir.h"

//從CBrowseDir派生出的子類,用來統計目錄中的文件及子目錄個數
classCStatDir:publicCBrowseDir
{
protected:
intm_nFileCount;//保存文件個數
intm_nSubdirCount;//保存子目錄個數

public:
//預設構造器
CStatDir()
{
//初始化數據成員m_nFileCount和m_nSubdirCount
m_nFileCount=m_nSubdirCount=0;
}

//返迴文件個數
intGetFileCount()
{
returnm_nFileCount;
}

//返回子目錄個數
intGetSubdirCount()
{
//因為進入初始目錄時,也會調用函數ProcessDir,
//所以減1後才是真正的子目錄個數。
returnm_nSubdirCount-1;
}

protected:
//覆寫虛函數ProcessFile,每調用一次,文件個數加1
virtualboolProcessFile(constchar*filename)
{
m_nFileCount++;
returnCBrowseDir::ProcessFile(filename);
}

//覆寫虛函數ProcessDir,每調用一次,子目錄個數加1
virtualvoidProcessDir
(constchar*currentdir,constchar*parentdir)
{
m_nSubdirCount++;
CBrowseDir::ProcessDir(currentdir,parentdir);
}
};

voidmain()
{
//獲取目錄名
charbuf[256];
printf("請輸入要統計的目錄名:");
gets(buf);

//構造類對象
CStatDirstatdir;

//設置要遍歷的目錄
if(!statdir.SetInitDir(buf))
{
puts("目錄不存在。");
return;
}

//開始遍歷
statdir.BeginBrowse("*.*");

//統計結果中,子目錄個數不含.及..
printf("文件總數:%d 子目錄總數:
%d ",statdir.GetFileCount(),
statdir.GetSubdirCount());
}

閱讀全文

與編程代碼的合集文件夾相關的資料

熱點內容
dvd光碟存儲漢子演算法 瀏覽:757
蘋果郵件無法連接伺服器地址 瀏覽:962
phpffmpeg轉碼 瀏覽:671
長沙好玩的解壓項目 瀏覽:144
專屬學情分析報告是什麼app 瀏覽:564
php工程部署 瀏覽:833
android全屏透明 瀏覽:737
阿里雲伺服器已開通怎麼辦 瀏覽:803
光遇為什麼登錄時伺服器已滿 瀏覽:302
PDF分析 瀏覽:484
h3c光纖全工半全工設置命令 瀏覽:143
公司法pdf下載 瀏覽:381
linuxmarkdown 瀏覽:350
華為手機怎麼多選文件夾 瀏覽:683
如何取消命令方塊指令 瀏覽:349
風翼app為什麼進不去了 瀏覽:778
im4java壓縮圖片 瀏覽:362
數據查詢網站源碼 瀏覽:150
伊克塞爾文檔怎麼進行加密 瀏覽:892
app轉賬是什麼 瀏覽:163